本文介绍了我如何触发一个动作,当用户按下回车键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果(在Android中)我有一个EditText中,我怎么能触发事件,当用户完成数据输入和点击返回/下一页?
我用下面的code都试过,但它似乎没有任何效果。我也得到一个从类型新extView.OnEditorActionListener(该方法onEditorAction(EditText上,INT,KeyEvent的)){}从不在本地使用的错误。
myEditText.setOnEditorActionListener(新EditText.OnEditorActionListener(){
公共布尔onEditorAction(的EditText V,INT actionId,KeyEvent的事件){
如果(actionId == EditorInfo.IME_ACTION_NEXT)
{
解决方案
我打了一下周围的各种事物,发现下面的作品code:
myEditText.setOnEditorActionListener(新OnEditorActionListener(){
@覆盖
公共布尔onEditorAction(TextView的V,INT actionId,KeyEvent的事件){
//做一些东西
}
});
If (in Android) I have an EditText box, how can I trigger an event when the user has finished entering data and hits return/Next?
I have tried using the code below but it seems to have no effect. I also get an 'The method onEditorAction(EditText, int, KeyEvent) from the type new extView.OnEditorActionListener(){} is never used locally' error.
myEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
public boolean onEditorAction(EditText v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT)
{
解决方案
I played around a bit with various things and found that the code below works:
myEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// Do some stuff
}
});
这篇关于我如何触发一个动作,当用户按下回车键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!