EditText显示错误文本
我遇到了一个非常奇怪的问题。我在对话框中有一个 editText。如果我打开一次对话框(点击 ListView 的一个元素)并执行一些操作,一切都可以。如果我下次打开对话框(点击 ListView 的不同元素),editText 将显示与第一次相同的值。
toast(profilesList.get(toEdit).get(NAME).toString()); //toast say Bob
et_profileName.setText(profilesList.get(toEdit).get(NAME).toString()); //I see Alice
另一个奇怪的事情:如果我旋转显示器,“BobAlice”中的文本就会改变。如果我关闭对话框,然后重新打开它,一切都会正常工作,并且对话框会显示正确的字符串。
有什么建议吗?
编辑: et_profileName 位于单击 ListView 中的项目时打开的对话框中。
更多代码:
protected Dialog onCreateDialog(int id) {
dialog = new Dialog(this);
...
et_profileName= (EditText)dialog.findViewById(R.id.et_profileName);
...
}
这是我调用对话框时的情况:
showDialog(DIALOG_EDIT_PROFILE);
toast(profilesList.get(toEdit).get(NAME).toString());
et_profileName.setText(profilesList.get(toEdit).get(NAME).toString());
,也不起作用
et_profileName= (EditText)dialog.findViewById(R.id.et_profileName);
如果我放在et_profileName.setText(...) 之前
i'm stuck whit a very strange problem. I have an editText in a dialog. If I open the dialog one time (tapping on a element of a ListView) and do some stuff all ok. If I open the dialog the next time (tapping on a different element of a ListView) the editText display the same value of the first time.
toast(profilesList.get(toEdit).get(NAME).toString()); //toast say Bob
et_profileName.setText(profilesList.get(toEdit).get(NAME).toString()); //I see Alice
Another strange thing: if I rotate the display the text change in "BobAlice". If I close the dialog, and then I reopen it, all work well and the dialog display the right Strings.
Any suggestions?
EDIT:
et_profileName is in a dialog that opens when you click an item in the ListView.
More code:
protected Dialog onCreateDialog(int id) {
dialog = new Dialog(this);
...
et_profileName= (EditText)dialog.findViewById(R.id.et_profileName);
...
}
Here is when I call the dialog:
showDialog(DIALOG_EDIT_PROFILE);
toast(profilesList.get(toEdit).get(NAME).toString());
et_profileName.setText(profilesList.get(toEdit).get(NAME).toString());
Also don't work if I put
et_profileName= (EditText)dialog.findViewById(R.id.et_profileName);
before the et_profileName.setText(...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决:
应该重写
onPrepareDialog(int id, Dialogdialog)
来准备一个托管对话框在显示之前。
添加此代码,它有效:
谢谢大家!
SOLVED:
Should override the
onPrepareDialog(int id, Dialog dialog)
to prepare amanaged dialog before it is being shown.
Added this code, it works:
Thanks you all!