我正在制作一个网球得分应用程序,我有两个问题:
如果得分为“40 - 40”,我怎样才能让得分之一显示出“优势”。
public class tennis extends Activity {
// Private member field to keep track of the count
int Count = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Left Counter//
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++;
if (Count==1){
countTextView.setText("15");}
else
if (Count== 2){
countTextView.setText("30");}
else
if (Count==3){
countTextView.setText("40");}
else
if (Count==4){
countTextView.setText("A");}
else {
countTextView.setText("0");}
};
});
}
}
答案 0 :(得分:1)
您可以尝试使用getText()来查看是否有优势,或者只使用更多Count if / else东西。
public void onClick(View v) {
CountA++;
if (CountA==1){
countATextView.setText("15");}
else
if (CountA== 2){
countATextView.setText("30");}
else
if (CountA==3){
countATextView.setText("40");}
else
if (CountA==4){
//Checks if BScore was Advantage initially and if AScore is 40
if (CountB==3 && ATextView.getText() =="40" && BTextView.getText() =="A")
{
countBTextView.setText("40");
CountA--
}
//Else if BScore is not A, and AScore is 40, set AScore to A
elseif(CountB==3 && BTextView.getText() !="A")
{
countATextView.setText("A");
CountA--
}
//Otherwise just reset score
else
{
countATextView.setText("0");
CountA = 0;
}
};
答案 1 :(得分:0)
重置点击次数的两个选项。检查Count> 5并在功能结束时将其重置为0或使用mod 5.我不确定你是如何跟踪那里的得分,但是当你更新得分并且给予优势时你可以检查40-40得分球员。