按键盘 ACTION_DONE 关闭 Android 首选项对话框
我希望能够关闭编辑首选项对话框(如下所示 http://twitpic.com/18ttdp )通过按键盘上的“完成”按钮。
目前,按“完成”只会关闭键盘,但会保留对话框。
在我的应用程序的其他部分,我使用类似于以下的代码来拦截“完成”按键并在我的活动中执行操作:
text.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
//do stuff here
return true;
}
return false;
}
});
但是,我不确定如何在我的首选项活动或布局 xml 中实现相同的效果。
I would like to be able to close the editpreference dialog (as shown here http://twitpic.com/18ttdp) by pressing the 'Done' button on the keyboard.
Currently, pressing 'Done' just dismisses the keyboard but leaves the dialog.
In other parts of my application I use code similar to the following to intercept the 'Done' key press and execute actions in my activity:
text.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
//do stuff here
return true;
}
return false;
}
});
However, I am unsure of how to do achieve this same effect in my preference activity or layout xml.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该执行类似以下操作,而不是在那里添加侦听器:
此代码将在按下某个键时关闭该对话框。
Instead of adding the listener there, you should do something similar to this:
This code will dismiss the dialog when a key is pressed.
我遇到了同样的问题,这就是我解决它的方法:
根据我的需要,输入是一个数字(因此是注释掉的行),但如果您想要文本,请使用那里的内容。
I had the same problem, this is how I solved it:
For my needs, the input was a number (hence the commented out line) but if you want text use what's there.
以下是我解决这个问题的方法:
但是您可能需要考虑子类化 EditTextPreference,因为这个 onClick 调用是一个 hack,并且它的实现将来可能会改变。
Here is how I solved it:
But you may want to consider subclassing EditTextPreference instead, since this onClick call is a hack, and its implementation may change in the future.