我在switch case语句中创建了一个AlertDialog,它在for循环中。在AlertDialog上有一个EditText用于输入。当弹出框时,for循环在后台运行。我希望循环等到发送输入继续。以下是AlertDialog的代码:
for(int i=0; i < code.length(); i++){
switch(code.charAt(i)){
case '+':
bytes[index]++;
break;
case '-':
bytes[index]--;
break;
case '<':
if(index > 0){
index--;
}else{
Toast.makeText(this, "Warning: Index is already at zero", Toast.LENGTH_LONG).show();
}
break;
case '>':
if(index <= 500){
index++;
}else{
Toast.makeText(this, "Warning: Maximum bytes reached", Toast.LENGTH_LONG).show();
}
break;
case ']':
if(loop == -1){
Toast.makeText(this, "ERROR: Close bracket before an open bracket!", Toast.LENGTH_LONG).show();
errors++;
break;
}else{
if(bytes[index] == 0){
loop = -1;
}else{
i = loop;
}
break;
}
case '[':
loop = i;
break;
case '.':
stdout(Character.toString((char)bytes[index]));
break;
case ',':
AlertDialog.Builder alert = new AlertDialog.Builder(this).setCancelable(false);
alert.setTitle("Enter Character");
alert.setMessage("Script is requesting input");
final EditText input = new EditText(this);
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(1);
input.setFilters(FilterArray);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setByte(input.getText().toString().charAt(0));
}
});
alert.show();
break;
}
if(errors > 0){
break;
}
}