当我改变方向,从纵向到横向我计算的结果正在消失。如何解决呢? [英] when i change the orientation from portrait to landscape my calculated result is disappearing. how to resolve it?
问题描述
上,在我的计算器应用程序,当我点击计算按钮,结果显示正常,但是当我改变计算的方位结果正在消失。
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.
推荐答案
请参阅本例中是如何使用的捆绑。首先,你必须重写<一href="http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState%28android.os.Bundle%29"相对=nofollow>的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);
}
在<一个href="http://developer.android.com/reference/android/app/Activity.html#onCreate%28android.os.Bundle%29"相对=nofollow>的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);
}
}
}
这篇关于当我改变方向,从纵向到横向我计算的结果正在消失。如何解决呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!