创建自定义分数

时间:2011-06-24 10:37:45

标签: android

我想制作一个网球得分应用但我不知道如何创建自定义得分(0,15,30,40,优势)?

以下是我用于其他“计数器”应用的代码:

public class counter extends Activity {

    // Private member field to keep track of the count
    private int Count = 0;


    /* Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final TextView countTextView = (TextView) findViewById(R.id.TextViewCount);
        final Button countButton = (Button) findViewById(R.id.ButtonCount);

        countButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                Count++;
                countTextView.setText("" + Count);
            }
        });
    }
}

1 个答案:

答案 0 :(得分:1)

更改:countTextView.setText("" + Count);

为:

If(Count == 1 || Count == 2){
  countTextView.setText("" + Count * 15);
} else if (Count ==3){
  countTextView.setText("" +40);
}else if (Count ==4){
  countTextView.setText("advantage");
} else {
  countTextView.setText("0");
}

你不应该用资本启动变量。

<强> CORRECTION

lCount++;
if (lCount ==1){
countTextViewPlusL.setText("15");}
else
if (lCount ==2){
countTextViewPlusL.setText("30");}
else {
if (lCount ==3){
countTextViewPlusL.setText("40");}
else
if (lCount ==4){
countTextViewPlusL.setText("ad");}
else {
countTextViewPlusL.setText("0");
}
}