当我改变方向,从纵向到横向我计算的结果正在消失。如何解决呢?当我、纵向、横向、如何解决

2023-09-04 09:17:01 作者:透明也褪色、

上,在我的计算器应用程序,当我点击计算按钮,结果显示正常,但是当我改变计算的方位结果正在消失。

Hai, in my calculator app when i click on calculate button result is appearing normally, but when i change the orientation calculated result is disappearing.

推荐答案

请参阅本例中是如何使用的捆绑。首先,你必须重写的onSaveInstanceState 方法。

Please see this example on how to save the state of your Activity using a Bundle. First you have to override the onSaveInstanceState method.

public void onSaveInstanceState(Bundle savedInstanceState) {
    TextView  txtName = (TextView)findViewById(R.id.raj44);
    String  aString = txtName.getText().toString();
    savedInstanceState.putString("Name", aString);
    super.onSaveInstanceState(savedInstanceState);
} 

在的onCreate 方法,你就可以从保存的捆绑恢复实例的状态。

In the onCreate method you can then restore the state of your instance from the saved Bundle.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.concretetool);
    if (savedInstanceState != null) {
        String  aString = savedInstanceState.getString("Name");
        if (aString != null) {
            txtName = (TextView)findViewById(R.id.raj44);
            txtName.setText(aString);
        }
    }
}