Android:输入文本时 EditText 不更新
我的应用程序中有以下内容:
layout/dialog_edit_group.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dlgEditGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/txtGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Group Name"
android:inputType="text"
android:singleLine="true"
android:editable="true"/>
我的活动(onCreateDialog 方法):
...
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.dialog_edit_group, (ViewGroup) findViewById(R.id.dlgEditGroup));
EditText txtGroup = (EditText) layout.findViewById(R.id.txtGroup);
txtGroup.setFocusable(true);
builder.setView(layout);
return builder.create();
当出现对话框并且我尝试键入文本时 - 编辑文本而不是更新。键盘显示按键已按下(我看到键盘提示 - 我使用姜饼键盘),但编辑文本没有任何变化。我需要做什么?
UPD:查看有问题的视频:youtu.be/XOSXDSZvisI
I have following in my app:
layout/dialog_edit_group.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dlgEditGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/txtGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Group Name"
android:inputType="text"
android:singleLine="true"
android:editable="true"/>
my activity (onCreateDialog method):
...
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.dialog_edit_group, (ViewGroup) findViewById(R.id.dlgEditGroup));
EditText txtGroup = (EditText) layout.findViewById(R.id.txtGroup);
txtGroup.setFocusable(true);
builder.setView(layout);
return builder.create();
When dialog appears and I try to type text - edit text not updates. Keyboard shows that keys are pressed (I see keyboard hints - I use gingerbread keyboard), but nothing changes in edittext. What I need to do?
UPD: see video with issue: youtu.be/XOSXDSZvisI
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这背后的主要原因可能是在您的清单文件中
主要问题在于清单文件中的这一行:
要使您在 editText 字段中输入的文本进行更新,请删除清单文件中的这一行文件:(
或)
将该行修改为:
我很晚才回答这个问题,但我希望这对于仍然面临这个问题的人来说可能会有用。
The main reason behind this is maybe in your manifest file
The main problem is with this line in your manifest file:
To make the text you have typed to be updated in the editText field remove this line in your manifest file:
(or)
Modify the line as:
I am answering this question late, but I hope that maybe it would be useful for who are still facing this problem.
您是否尝试过在添加视图后将 EditText 设置为可聚焦?
Have you tried setting the EditText to focusable AFTER adding the view?
setFocusable(true);
只是使小部件可聚焦,并且在EditText
的情况下默认情况下可聚焦。请尝试 requestFocus() 。
setFocusable(true);
just makes the widget focusable and in the case ofEditText
is focusable by default.Try requestFocus() instead.
我的 HTC Desire 上也出现此错误,但是当我等待大约 1-2 分钟时,所有编辑文本在一些系统操作系统日志后都可以正常工作。所以,我认为问题不在于你的代码。
I have got this error on my HTC Desire too, but when I wait about 1-2 min, all edittext work normal after some system os log. So, I think problem is not your code.
对于那些仍在寻找这个答案的人,我通过将 EditText 的颜色设置为黑色解决了我的问题
For those still looking for this answer, I solved my problem by setting color of EditText to BLACK