EditText Settext not working with Fragment(EditText Settext 不适用于片段)
问题描述
我有一个屏幕的 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 不适用于片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:EditText Settext 不适用于片段
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
