我有一个屏幕的 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模板网!
EditText:禁用文本选择处理程序单击事件上的粘贴EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本选择处理程序单击事件上的粘贴/替换菜
2.3 上带有完成 SoftInput 操作标签的多行 EditTextMultiline EditText with Done SoftInput Action Label on 2.3(2.3 上带有完成 SoftInput 操作标签的多行 EditText)
如何在 Android 中检测向左或向右滑动?How to detect the swipe left or Right in Android?(如何在 Android 中检测向左或向右滑动?)
防止在Android中的屏幕旋转对话框解除Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋转对话框解除)
如何处理 ImeOptions 的完成按钮点击?How do I handle ImeOptions#39; done button click?(如何处理 ImeOptions 的完成按钮点击?)
您如何将 EditText 设置为仅接受 Android 中的数值How do you set EditText to only accept numeric values in Android?(您如何将 EditText 设置为仅接受 Android 中的数值?)