onResume() 时清除 EditText
我正在创建一个应用程序,如果用户以任何方式离开应用程序并返回,我希望清除所有 EditText 字段。
我创建了一些我认为可行的代码:
@Override
public void onResume {
super.onResume;
(EditText)findViewById(R.id.NumberEntry).setText("");
(EditText)findViewById(R.in.NameEntry).setText("");
}
但是,当我单击“帮助”菜单(通过 onMenuItemSelected()
完成)并请求帮助时,应用程序会获取帮助文件并准备好绘制但随后崩溃。我不明白为什么。任何建议将不胜感激。
或者如果有人有其他可行的方法。
谢谢
I am creating an app where if the user leaves the app by any means and returns, I would like all the EditText fields cleared.
I have created some code that I thought would work which is:
@Override
public void onResume {
super.onResume;
(EditText)findViewById(R.id.NumberEntry).setText("");
(EditText)findViewById(R.in.NameEntry).setText("");
}
However when I click on the Help menu (done through onMenuItemSelected()
) and ask for help the app gets the help file and gets it ready to draw but then crashes. I can't figure out why. Any advice would be appreciated.
Or if anyone has another method that will work.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 R.in 不熟悉,您的意思是输入 R.id.NameEntry 吗?
I'm not familiar with R.in, did you mean to type R.id.NameEntry?
除了 theisenp 所说的拼写错误之外,您可能还需要将视图转换为 EditText 的 before 调用 setText -
请注意额外的一组括号。
In addition to the typo theisenp said, you may need to cast the views to EditText's before calling setText --
Notice the extra set of parenthesis.