【发布时间】:2011-07-29 22:28:26
【问题描述】:
我希望触发一个 while 循环,但前提是用户选择了一个选项。现在出于某种原因,它甚至在用户选择一个选项之前就自动浏览了整个代码块。如何强制它等到用户选择某些内容后再继续?
case R.id.buttonSetPlayers:
//**********************//
//***SET PLAYER COUNT***//
//**********************//
AlertDialog.Builder builderPC = new AlertDialog.Builder(this);
final CharSequence[] playerCount = {"1", "2", "3", "4"};
builderPC.setTitle("Player Count");
builderPC.setItems(playerCount, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface, int item) {
Toast.makeText(getApplicationContext(), playerCount[item], Toast.LENGTH_SHORT).show();
if (playerCount[item].equals("1")){
EntryScreen.this.totalPlayerCount = 1;
}
else if (playerCount[item].equals("2")){
EntryScreen.this.totalPlayerCount = 2;
}
else if (playerCount[item].equals("3")){
EntryScreen.this.totalPlayerCount = 3;
}
else if (playerCount[item].equals("4")){
EntryScreen.this.totalPlayerCount = 4;
}
return;
}
});
builderPC.create().show();
###
I want it to wait to do this next part instead of doing it as soon as button is clicked. Below...
###
while (totalPlayerCount >= 1){
setNames();
totalPlayerCount--;
}
return;
【问题讨论】:
-
我觉得这个问题有点不清楚,你是在等待
builderPC.create().show();阻止吗? -
抱歉,我的评论下方的 while 循环是我不想触发的,直到用户选择了 1-4。然后我需要这个过程循环很多次。
标签: android loops button while-loop option