我正在尝试清理我的代码,以使其在'部分'下运行。 有一个叫intro()
,另外一个叫second()
等..代码行被忽略
的问题是当我从代码(intro()
)第一部分切换到下一个一个(second()
)的应该先运行清洁代码,但不是真的!
的code
基本上在list
应该看起来像一个聊天写入文本,所以intro()
是文本的第一部分,那么就应该清除聊天并开始编写内部second()
其他文本。
这是我的代码,我们来看一看:
int counter;
boolean introDone = false;
//Intro
public void intro(){
write(answers[counter], buttonText[counter]);
}
public void second(){
write("So these are the rules:", R.string.go);
}
public void hello(View view){
Toast toast = Toast.makeText(this, Integer.toString(counter), Toast.LENGTH_SHORT);
toast.show();
if(counter <= 2){
intro();
}else if(counter == 3){
clear();
}else if (counter > 2 && counter < 5) {
second();}
counter++;
}
}
这奏效了:
//Intro
public void intro(){
write(answers[counter], buttonText[counter]);
}
public void second(){
write("So these are the rules:", R.string.go);
}
public void hello(View view) {
Toast toast = Toast.makeText(this, Integer.toString(counter), Toast.LENGTH_SHORT);
toast.show();
if (counter <= 2) {
intro();
} else if(counter == 3) {
introDone = true;
}
if (introDone) {
clear();
introDone = false;
}
if (counter > 2 && counter < 5) {
second();
}
counter++;
}
}
尝试if(introDone == true)..如果这样不起作用,那么ti意味着您的IntroDone为false。 – Kristo
@ Kristo1990如何将if(introDone)改为if(introDone == true)会改善什么?这两个代码将以相同的方式工作,并且您的提议仅引入了像if(introDone = true)那样的错字错误的可能性,这就是为什么应该避免使用'== true'的原因。 – Pshemo
这似乎并没有改变@ Kristo1990 – FET