EditText上的setText不工作片段 [英] EditText Settext not working with Fragment
问题描述
我有一个屏幕的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());
我点击编辑按钮从View模式来打开编辑模式。我在这里改变实体名称和保存。这使我回查看屏幕。但我发现的实体名称不更新。
我调试,发现 entity.getEntityname()
是有正确的值。我不知道为什么编辑文本不采取新的价值。
I click on 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.
任何想法?
注:我使用的Android版本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不工作片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!