更改方向时的松散日期

时间:2011-11-23 13:55:24

标签: android

  

可能重复:
  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。有没有办法做到这一点?有什么帮助吗?

1 个答案:

答案 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";