問題描述
我有一個屏幕的 3 種狀態(tài)的片段;添加、編輯和查看.在添加中,我創(chuàng)建一個實體并保存它.下次我在查看模式下打開它并使用
I have fragments for 3 states of a screen; Add, Edit and View. In Add, I create an entity and save it. Next time I open it in View mode and set the entity name using
EditText entityName = (EditText) view.findViewById(R.id.entityName);
entityName.setText(entity.getEntityname());
我從查看模式單擊編輯按鈕以打開編輯模式.我在這里更改實體名稱并保存.這讓我回到了視圖屏幕.但我發(fā)現(xiàn)實體名稱沒有更新.我調(diào)試并發(fā)現(xiàn) entity.getEntityname()
具有正確的值.我不確定為什么編輯文本沒有采用新值.
I click on the edit button from View mode to open the Edit mode. I change the entity name here and save it. This brings me back to the view screen. But I find the entity name is not updated.
I debug and found that entity.getEntityname()
is having correct value. I am not sure why the edit text does not take new value.
有什么想法嗎?
注意:我使用的是安卓 2.2 版
Note: I am using android version 2.2
推薦答案
EditText 似乎在重置 onCreateView
中的文本時出現(xiàn)問題.所以這里的解決方案是重置onResume
中的文字.這行得通.
The EditText appears to have an issue with resetting text in onCreateView
. So the solution here is to reset the text in onResume
. This works.
onActivityCreated 也有問題.我在 onStart 中重置了 edittext 的內(nèi)容,它可以工作.[感謝@savepopulation]
Also there's an issue in onActivityCreated. I reset edittext's content in onStart and it works. [credits to @savepopulation]
這篇關(guān)于EditText Settext 不適用于片段的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!