我知道這已經被問了很多次,但沒有答案可以幫助我。AlertDialog輪流重新出現
我有一個對話框會彈出在某個時刻(當我調用方法「showServerDialog」)。 顯示對話框,一切都很好,直到我使用「negativeButton」消除對話框,然後旋轉屏幕。然後,雖然我駁回了該對話框,但對話框再次出現。
我讀了很多次,如果我使用showDialog(int id)方法顯示對話框並重寫onCreateDialog(int id)方法,android會自動處理所有內容。而這正是我在做什麼:
@SuppressWarnings("deprecation")
public void showServerDialog(int position){
showDialog(REMOVE_SERVER_DIALOG_ID);
}
@SuppressWarnings("deprecation")
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case REMOVE_SERVER_DIALOG_ID:
System.out.println("---------------------------------DIALOG");
// Create AlterDialog
Builder builder = new AlertDialog.Builder(this);
builder.setMessage("This will end the activity");
builder.setCancelable(true);
builder.setPositiveButton("I agree", new OkOnClickListener());
builder.setNegativeButton("No, no", new CancelOnClickListener());
AlertDialog dialog = builder.create();
dialog.show();
return dialog;
}
return super.onCreateDialog(id);
}
private final class CancelOnClickListener implements DialogInterface.OnClickListener{
public void onClick(DialogInterface dialog, int which) {
// Do nothing and just close dialog
}
}
但是,當我關閉對話框,通常使用對話框中的按鈕和旋轉屏幕那麼它只是重新出現。
我完全沉迷於此。請幫忙。
我真的不想添加這個,因爲我仍然希望我的應用程序在旋轉時再次創建自己。 – JustABit