我有一个屏幕的 3 种状态的片段;添加、编辑和查看.在添加中,我创建一个实体并保存它.下次我在查看模式下打开它并使用
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());
我从查看模式单击编辑按钮以打开编辑模式.我在这里更改实体名称并保存.这让我回到了视图屏幕.但我发现实体名称没有更新.我调试并发现 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
中的文本时出现问题.所以这里的解决方案是重置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 的内容,它可以工作.[感谢@savepopulation]
Also there's an issue in onActivityCreated. I reset edittext's content in onStart and it works. [credits to @savepopulation]
这篇关于EditText Settext 不适用于片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!