在我的應用程序中,我有一個45「editText」。現在,當用戶旋轉設備時,對話框關閉,所有數據都消失了。所以我在Dialogclass中創建了一個「public static boolean isShow = false」變量,它的確是對話框是「show」,並且在我的MainActivity上我保存到包中,它的工作原理我的對話框沒有關閉,因爲我創建了一個新的對話框, isShow「= false。但所有數據都清除了。我的問題是我需要一個接一個保存所有45個editText嗎?如果我需要,有一種方法可以取消只對這個對話框的旋轉?如何在對話框類上保存實例狀態?
public class DialogSetting extends Dialog {
public static boolean isShow = false;
public DialogSetting(Context context) {
super(context);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_setting);
this.context = context;
this.show();
isShow = true;
this.setOnCancelListener(new DialogInterface.OnCancelListener()
{
@Override
public void onCancel(DialogInterface dialog)
{
isShow = false;
}
});
}
public void close(View v){
isShow = false;
this.dismiss();
}
MainActivity:
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
outState.putBoolean("dialogSetting", DialogSetting.isShow);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
DialogSetting.isShow = savedInstanceState.getBoolean("dialogSetting");
if(DialogSetting.isShow){
new DialogSetting(this);
}
我不明白什麼不同,什麼更好,在我的問題,我想跳過editText保存實例的一部分因爲我有很多edittext – Matt 2014-09-04 13:18:48
好吧,這是好事。 'FragmentManager'也保留了'EditText'的輸入。所以你不必手動保存輸入。我的不好;) – reVerse 2014-09-04 14:34:29
好吧,ID不知道謝謝:) – Matt 2014-09-05 01:00:01