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

如何在方向更改時(shí)保留 EditText 數(shù)據(jù)?

How to retain EditText data on orientation change?(如何在方向更改時(shí)保留 EditText 數(shù)據(jù)?)
本文介紹了如何在方向更改時(shí)保留 EditText 數(shù)據(jù)?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

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

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() 方法中都調(diào)用了 setContentView() 方法.它滿足我的兩個(gè)要求.布局已更改,EditTexts 中的輸入數(shù)據(jù)也保持原樣.但它有一個(gè)大問(wèn)題:

(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 :

當(dāng)用戶點(diǎn)擊登錄按鈕時(shí),ProgressDialog 會(huì)顯示,直到收到服務(wù)器響應(yīng).現(xiàn)在,如果用戶在 ProgressDialog 運(yùn)行時(shí)旋轉(zhuǎn)設(shè)備,應(yīng)用程序會(huì)崩潰.它顯示一個(gè)異常說(shuō)視圖不能附加到窗口".我嘗試使用 onSaveInstanceState 處理它(在方向更改時(shí)會(huì)調(diào)用它),但應(yīng)用程序仍然崩潰.

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 - 在這種方法中,我在清單中提供了方向".所以現(xiàn)在我有兩種情況:

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

(a) 如果我在 onCreate() 和 onConfigurationChanged() 中調(diào)用 setContentView() 方法,布局會(huì)相應(yīng)更改,但 EditText 數(shù)據(jù)會(huì)丟失.

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

(b) 如果我在 onCreate() 中調(diào)用 setContentView() 方法,但在 onConfigurationChanged() 中沒(méi)有調(diào)用,則 EditText 數(shù)據(jù)不會(huì)丟失,但布局也不會(huì)相應(yīng)更改.

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

在這種方法中,甚至不會(huì)調(diào)用 onSaveInstanceState().

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

所以我處于一個(gè)非常可怕的境地.這個(gè)問(wèn)題有什么解決辦法嗎?請(qǐng)幫忙.提前謝謝.

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

推薦答案

在onConfigurationChanged方法中,先在全局變量中獲取兩個(gè)編輯文本的數(shù)據(jù),然后調(diào)用setContentView方法.現(xiàn)在將保存的數(shù)據(jù)再次設(shè)置到編輯文本中.

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.

這篇關(guān)于如何在方向更改時(shí)保留 EditText 數(shù)據(jù)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
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 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問(wèn)題)
主站蜘蛛池模板: 久久久久久久一区 | 性网址| av免费网址 | 国产一区不卡 | 亚洲精选一区二区 | 91在线观看 | 欧美精品在欧美一区二区 | 欧美国产视频 | 麻豆精品一区二区三区在线观看 | 夜夜操天天艹 | 福利一区二区在线 | 九九亚洲| 成人免费在线播放视频 | 天天干天天干 | 色综合一区二区三区 | 涩涩导航 | 国产在线精品一区二区 | 精品久久影院 | 欧美一级在线观看 | 成人久久 | 欧美中文字幕在线观看 | 国产精品一区二区三区四区 | 国产日韩欧美一区 | 欧美性一级 | a黄毛片| 久久国产成人 | 日韩欧美中文字幕在线观看 | 日韩精品在线看 | 精品人伦一区二区三区蜜桃网站 | 亚洲成人一区 | 亚洲第一在线视频 | 欧美午夜一区 | 久久久久久毛片免费观看 | 九九久久精品视频 | 国产永久免费 | 毛片网站在线观看 | 日韩视频免费看 | 国产精品久久久久久吹潮 | 国产精品1区| 精精久久| 欧美精品一区二区三区在线 |