顯示我在機器人工作室的AlertDialog
,如下所示:AlertDialog不在機器人工作室
final EditText columninput = new EditText(this);
columninput.setInputType(InputType.TYPE_CLASS_NUMBER);
AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setTitle("Choose column number");
adb.setView(columninput);
adb.setMessage("Please specify the number of columns you would like to decrypt your message with.");
adb.setCancelable(true);
adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
boolean bool = true;
try {
col = Integer.parseInt(columninput.getText().toString());
}
catch (Exception e) {
bool = false;
Toast t = Toast.makeText(getApplicationContext(), "Incorrect input", Toast.LENGTH_LONG);
t.show();
}
if (bool) {
dialog.dismiss();
}
}
});
adb.show();
method1(toRead, col);
注意toRead
是另一變量處理這方面的外部;它不應該導致任何錯誤。當我運行我的應用程序時,AlertDialog
從不顯示,並且method1
立即運行。但是,當我註釋掉最後一行(method1(toRead, col)
)時,將在應用程序運行時顯示alertdialog。爲什麼會這樣,我如何確保始終顯示alertDialog?
以及....然後張貼的方法1,請... – Opiatefuchs
找出來,張貼方法1的'()的代碼'還要注意,在顯示對話框時,如果你想從對話框中得到結果以便在另一個方法中使用它,例如'method1()'你不能這樣做,你需要使用dialog對話框來調用無論是父母的回調,還是調用method1()本身。 – Yazan
我會發布method1(),但它很長(超過300行代碼!)。我已經測試了它自己,但我相當確信它不應該是任何錯誤的來源... – Eragon20