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 不适用于片段
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
