create custom score
I want to make a tennis score app but i don't kn开发者_JS百科ow how to create a custom score (0, 15, 30, 40, advantage)?
Here is the code I've used with an other "counter" app:
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);
}
});
}
}
Change: countTextView.setText("" + Count);
to:
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");
}
And you shouldn't start variables with a capital either.
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");
}
}
精彩评论