海,在我的計算器應用程序,當我點擊計算按鈕結果正常出現,但是當我改變方向計算結果正在消失。當我將縱向從縱向改爲橫向時,我的計算結果正在消失。如何解決它?
6
A
回答
2
請參閱有關如何使用Bundle保存您的活動的狀態這個例子。首先你必須重寫onSaveInstanceState方法。
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方法,你可以再從保存的捆綁恢復實例的狀態。
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);
}
}
}
0
活動在方向更改後重新啓動。你必須保存在束
的電流值(我假設你的意思是一個Android應用程序)
3
試試這個代碼
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
,並在manifest.xml
<application android:icon="@drawable/icon" android:label="@string/app_name">´
<activity android:name="XXXXX"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> //this <--
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</application>
編輯: 我增加了屏幕尺寸的標誌。在android> 3中,如果你不添加這個標誌,onConfigurationChanged方法將不會被調用。
相關問題
- 1. UITableView在從縱向,橫向,縱向旋轉時更改尺寸
- 2. 當從橫向到縱向改變方向時,縱向滑塊寬度減小
- 3. 更改爲縱向/橫向時,ImageView消失
- 4. 當從縱向更改爲橫向視圖時,表視圖消失xcode
- 5. 將元素的方向從縱向更改爲橫向
- 6. popViewControllerAnimated:從橫向到縱向
- 7. iphone:從縱向到橫向
- 8. 將我的項目從縱向轉換爲橫向的問題
- 9. 如何以橫向適應縱向圖像在縱橫比保持縱橫比
- 10. 如何將Reveal.js方向更改爲縱向或縱向?
- 11. iPad從縱向轉爲橫向
- 12. 當縱向xib調整爲橫向時,需要更改UIScrollView contentSize
- 13. 將視圖從縱向更改爲橫向時,方向不會更改
- 14. iPad - 縱向和橫向 - 計算它與我的桌子做多少角度
- 15. 將設備方向從橫向更改爲縱向時在x軸上溢出
- 16. Android:如何處理縱向反轉縱向和橫向反轉橫向事件
- 17. 如何計算的圖像是橫向還是縱向
- 18. 如何將縱向視圖更改爲橫向模式?
- 19. 僅在將方向更改爲橫向並返回縱向後,才能正確顯示縱向佈局
- 20. NavigationController橫向和縱向
- 21. 縱向和橫向滑動
- 22. 縱向和橫向居中
- 23. 維持橫向/縱向
- 24. UIDeviceOrientationFaceUp - 如何區分縱向和橫向?
- 25. 如何更改縱向和橫向的模擬器方向?
- 26. 我如何在乳膠中縱向和橫向放置報價?
- 27. 當方向從縱向變爲橫向時,視頻從Android開始開始?
- 28. 如何從縱向模式更改爲橫向模式並鎖定它?
- 29. 如果以前的視圖爲橫向,則爲強制縱向
- 30. 在iOS中將圖像從縱向調整爲橫向模式
+1好一個....和易於使用 – BBdev 2012-10-19 11:54:45
@BBdev我添加了一個新的國旗screenSize。如果你不在Android> 3中添加它,該方法將不會被調用 – Aracem 2012-12-03 09:19:13