1
我已经检查了很多帖子,并根据我已经完成的方向变更编码。当方向更改时,问题是我无法检索TextView中输入的值。任何人都可以告诉我哪里出错了?如何存储值并在方向更改时检索它?
编码:
在用于相应的活动余加入清单文件:
android:configChanges="orientation|keyboardHidden"
在活动中,添加以下方法:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_screen);
//Initialized the widgets
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//have written separate layout files for portrait and landscape
setContentView(R.layout.home_screen);
//Initialized the widgets again
retrieveSavedState(); //sets the TextViews again
}
@Override
protected void onPause() {
super.onPause();
saveState(); //save the TextView values
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
saveState();
}
@Override
protected void onResume() {
super.onResume();
retrieveSavedState();
}
上述方法并没有帮助我!我最后使用了SharedPreference。它与...一起工作... – Mathew