0

我保存并恢复视图,但我丢失了编辑文本、复选框等。使用调试器,我可以看到所有这些字段都在“savedInstanceState”(在恢复部分)中,但没有显示;也许 setcontentview 还不够?预先感谢您的帮助。米歇尔F

@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState.putInt("Screen",screenFlag);
    savedInstanceState.putInt("PreviousScreen",previous_screenFlag);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    screenFlag = savedInstanceState.getInt("Screen");
    previous_screenFlag = savedInstanceState.getInt("PreviousScreen");
    switch (screenFlag){
        case 1:
            setContentView(R.layout.lay1);
            break;
        case 2:
            setContentView(R.layout.dlay2);
            break;
        case 3:
            setContentView(R.layout.lay3);
            break;
        default:
            home(null);
    }
}
4

0 回答 0