Java 禁用onClick直到int=something public类MainActivity扩展了AppCompatActivity{ int foulCounterA=0; int scoreOnePointTeamA=0; int periodCount=0; 私有文本视图tv1; 私密文本浏览期; 专用按钮startbtn、cancelbtn; 专用开关按钮开关; 私有布尔值isPaused=false; 私有布尔值isCanceled=false; 私有长剩余时间=0; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv1=(TextView)findViewById(R.id.tv1); period=(TextView)findViewById(R.id.period\u编号); startbtn=(按钮)findViewById(R.id.startbtn); cancelbtn=(按钮)findViewById(R.id.cancelbtn); togbtn=(ToggleButton)findviewbyd(R.id.togbtn); cancelbtn.setEnabled(假); togbtn.setEnabled(false); startbtn.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图){ foulCounterA=0; foulCounterB=0; 显示forteamafoul(foulCounterA); displayForTeamBFoul(foulCounterB); 如果(周期计数
我想让java代码尽可能简单,所以我刚刚为我的问题添加了几行代码。我想做的是Java 禁用onClick直到int=something public类MainActivity扩展了AppCompatActivity{ int foulCounterA=0; int scoreOnePointTeamA=0; int periodCount=0; 私有文本视图tv1; 私密文本浏览期; 专用按钮startbtn、cancelbtn; 专用开关按钮开关; 私有布尔值isPaused=false; 私有布尔值isCanceled=false; 私有长剩余时间=0; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv1=(TextView)findViewById(R.id.tv1); period=(TextView)findViewById(R.id.period\u编号); startbtn=(按钮)findViewById(R.id.startbtn); cancelbtn=(按钮)findViewById(R.id.cancelbtn); togbtn=(ToggleButton)findviewbyd(R.id.togbtn); cancelbtn.setEnabled(假); togbtn.setEnabled(false); startbtn.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图){ foulCounterA=0; foulCounterB=0; 显示forteamafoul(foulCounterA); displayForTeamBFoul(foulCounterB); 如果(周期计数,java,android,Java,Android,我想让java代码尽可能简单,所以我刚刚为我的问题添加了几行代码。我想做的是 android:onClick=“onePointForTeamA”仅当foulCounterA=5添加if(foulCounterA=5)失败时,才可单击此按钮内部Teama公共无效FoulCount(视图五){ 这样就给了我一个错误。表示required:boolean,find:int. 我应该如何处理代码?对于您的具体问题,我们将提供任何帮助,因为等式检查必须由==运算符进行,所以if(foulCounterA
android:onClick=“onePointForTeamA”
仅当foulCounterA=5
添加
if(foulCounterA=5)失败时,才可单击此按钮代码>内部<代码>Teama公共无效FoulCount(视图五){
这样就给了我一个错误。表示required:boolean,find:int.
我应该如何处理代码?对于您的具体问题,我们将提供任何帮助,因为等式检查必须由==运算符进行,所以if(foulCounterA=5);的语法是错误的 因此正确的语法应该是if(foulCounterA==5) 正如@OH GOD spider在评论中所说的,您应该检查java操作符的基础知识
另外,我建议您在提出新问题之前先搜索答案。您应该看一本关于运算符的非常基本的java教程:-并特别注意
赋值
和相等
运算符之间的区别
public class MainActivity extends AppCompatActivity {
int foulCounterA = 0;
int scoreOnePointTeamA = 0;
int periodCount = 0;
private TextView tv1;
private TextView period;
private Button startbtn, cancelbtn;
private ToggleButton togbtn;
private boolean isPaused = false;
private boolean isCanceled = false;
private long remainingTime = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.tv1);
period = (TextView) findViewById(R.id.period_number);
startbtn = (Button) findViewById(R.id.startBtn);
cancelbtn = (Button) findViewById(R.id.cancelBtn);
togbtn = (ToggleButton) findViewById(R.id.togBtn);
cancelbtn.setEnabled(false);
togbtn.setEnabled(false);
startbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
foulCounterA = 0;
foulCounterB = 0;
displayForTeamAFoul(foulCounterA);
displayForTeamBFoul(foulCounterB);
if (periodCount < 3)
periodCount = periodCount + 1;
else periodCount = 4;
period.setText("Period " + periodCount);
startbtn.setEnabled(false);
cancelbtn.setEnabled(true);
togbtn.setEnabled(true);
isPaused = false;
isCanceled = false;
long millisInFuture = 20000; /////20sec
long countDownInterval = 1000; /////1sec
new CountDownTimer(millisInFuture, countDownInterval) {
@Override
public void onTick(long millisUntilFinished) {
if (isPaused || isCanceled) {
cancel();
} else {
tv1.setText("" + millisUntilFinished / 1000);
remainingTime = millisUntilFinished;
}
}
@Override
public void onFinish() {
startbtn.setEnabled(true);
togbtn.setEnabled(false);
if (periodCount < 4)
tv1.setText("Times up!");
else tv1.setText("Game Over!");
}
}.start();
}
});
togbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (togbtn.isChecked()) {
isPaused = true;
} else {
isPaused = false;
long millisInFuture = remainingTime;
long countDownInterval = 1000; /////1sec
new CountDownTimer(millisInFuture, countDownInterval) {
@Override
public void onTick(long millisUntilFinished) {
if (isPaused || isCanceled) {
cancel();
} else {
tv1.setText("" + millisUntilFinished / 1000);
remainingTime = millisUntilFinished;
}
}
@Override
public void onFinish() {
startbtn.setEnabled(true);
togbtn.setEnabled(false);
if (periodCount < 4)
tv1.setText("Times up!");
else tv1.setText("Game Over!");
}
}.start();
}
}
});
cancelbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isCanceled = true;
period.setText("Period");
tv1.setText("Timer");
startbtn.setEnabled(true);
togbtn.setEnabled(false);
cancelbtn.setEnabled(false);
foulCounterA = 0;
foulCounterB = 0;
periodCount = 0;
displayForTeamAFoul(foulCounterA);
displayForTeamBFoul(foulCounterB);
}
});
}
public void onePointForTeamA(View v) {
scoreTeamA = scoreTeamA + 1;
scoreOnePointTeamA = scoreOnePointTeamA + 1;
displayForTeamA(scoreTeamA);
displayForTeamAOnePoint(scoreOnePointTeamA);
}
public void foulCountForTeamA(View v) {
if (foulCounterA < 5)
foulCounterA = foulCounterA + 1;
else
foulCounterA = 5;
displayForTeamAFoul(foulCounterA);
}
public void displayForTeamAOnePoint(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_a_score_1_point);
scoreView.setText(String.valueOf(score));
}
public void displayForTeamAFoul(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_a_foul);
scoreView.setText(String.valueOf(score));
}
}