久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在方向更改時保留 EditText 數據?

How to retain EditText data on orientation change?(如何在方向更改時保留 EditText 數據?)
本文介紹了如何在方向更改時保留 EditText 數據?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個登錄屏幕,其中包含 2 個用于用戶名和密碼的 EditText.我的要求是,在方向更改時,EditText 中的輸入數據(如果有)應保持原樣,并且還應繪制新布局.我有 2 個布局 xml 文件 - 一個位于布局文件夾中,另一個位于在布局土地文件夾中.我正在嘗試實現以下兩種方法,但它們都不是完美的:

I have a Login screen which consists of 2 EditTexts for Username and Password. My requirement is that on orientation change , input data(if any) in EditText should remain as it is and a new layout should also be drawn. I have 2 layout xml files- one in layout folder and other in layout-land folder. I am trying to implement following 2 approaches but none of them is perfect:

(1) configChanges:keyboardHidden - 在這種方法中,我不在清單文件的 configChanges 中提供方向".所以我在 onCreate() 和 onConfigurationChanged() 方法中都調用了 setContentView() 方法.它滿足我的兩個要求.布局已更改,EditTexts 中的輸入數據也保持原樣.但它有一個大問題:

(1) configChanges:keyboardHidden - In this approach, I don't provide "orientation" in configChanges in manifest file. So I call setContentView() method in both onCreate() and onConfigurationChanged() methods. It fulfills both my requirements. Layout is changed and input data in EditTexts also remains as it is. But it has a big problem :

當用戶點擊登錄按鈕時,ProgressDialog 會顯示,直到收到服務器響應.現在,如果用戶在 ProgressDialog 運行時旋轉設備,應用程序會崩潰.它顯示一個異常說視圖不能附加到窗口".我嘗試使用 onSaveInstanceState 處理它(在方向更改時會調用它),但應用程序仍然崩潰.

When user clicks on Login button, a ProgressDialog shows until server-response is received. Now if user rotates the device while ProgressDialog is running, app crashes. It shows an Exception saying "View cannot be attached to Window." I have tried to handle it using onSaveInstanceState (which DOES get called on orientation change) but app still crashes.

(2) configChanges:orientation|keyboardHidden - 在這種方法中,我在清單中提供了方向".所以現在我有兩種情況:

(2) configChanges:orientation|keyboardHidden - In this approach, I provide "orientation" in manifest. So now I have 2 scenarios:

(a) 如果我在 onCreate() 和 onConfigurationChanged() 中調用 setContentView() 方法,布局會相應更改,但 EditText 數據會丟失.

(a) If I call setContentView() method in both onCreate() and onConfigurationChanged(), Layout is changed accordingly but EditText data is lost.

(b) 如果我在 onCreate() 中調用 setContentView() 方法,但在 onConfigurationChanged() 中沒有調用,則 EditText 數據不會丟失,但布局也不會相應更改.

(b) If I call setContentView() method in onCreate() , but not in onConfigurationChanged(), then EditText data is not lost but layout also not changes accordingly.

在這種方法中,甚至不會調用 onSaveInstanceState().

And in this approach, onSaveInstanceState() is not even called.

所以我處于一個非常可怕的境地.這個問題有什么解決辦法嗎?請幫忙.提前謝謝.

So I am in a really intimidating situation. Is there any solution to this problem? Please help. Thanx in advance.

推薦答案

在onConfigurationChanged方法中,先在全局變量中獲取兩個編輯文本的數據,然后調用setContentView方法.現在將保存的數據再次設置到編輯文本中.

in onConfigurationChanged method, first get the data of both the edit texts in global variables and then call setContentView method. Now set the saved data again into the edit texts.

這篇關于如何在方向更改時保留 EditText 數據?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 亚洲成人播放器 | 国产97在线看 | 一久久久 | 男女羞羞视频在线免费观看 | 日本超碰| 高清视频一区二区三区 | 欧美a∨| 日韩精品一区二区不卡 | 激情一区二区三区 | 一级黄a视频 | 日韩国产一区二区三区 | 欧美区在线 | 日韩欧美国产一区二区三区 | 亚洲午夜视频 | 久久国产精品久久久久 | 欧美一级免费看 | 欧美黄色片| 国产高清免费视频 | 日韩国产欧美一区 | 日韩免费一区 | 久久综合av | 日本中文字幕在线观看 | www国产成人免费观看视频,深夜成人网 | 欧美精品一区在线发布 | 国产日韩欧美一区二区 | 欧美国产日韩在线观看成人 | 99国产精品久久久 | 国产一区 | 亚洲精品一区二区冲田杏梨 | a黄毛片| www国产成人免费观看视频 | 伊人精品一区二区三区 | 亚洲欧美激情精品一区二区 | 亚洲逼院| 亚洲视频免费在线看 | 水蜜桃亚洲一二三四在线 | 亚洲精品日韩欧美 | 国产精品无码永久免费888 | 国产精品我不卡 | 亚洲视频一区二区三区四区 | 中文字幕在线免费 |