可能重复:
when i change the orientation from portrait to landscape my calculated result is disappearing. how to resolve it?
EditText is losing users' input when rotating android phone
在我的应用程序中,我有一个EditText。在纵向模式下,我输入字母,当我旋转设备时,我看到空的Edittext。有没有办法做到这一点?有什么帮助吗?
答案 0 :(得分:0)
将数据保存在
中public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putString("MyText", edtMyText.getText().toString());
}
并在OnCreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
if (savedInstanceState != null) {
String myString = savedInstanceState.getString("MyText");
edtMyText.setText(myString);
}
}
为清楚起见,您可能需要定义
private static final String MYTEXT_SAVED_ITEM = "MyText";