安卓:编辑文本GO按钮 [英] Android: Edit Text Go Button

查看:123
本文介绍了安卓:编辑文本GO按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下定义的编辑文本。

I have an Edit Text that is defined as follows.

<EditText  
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text" 
android:hint="@string/field_text"
android:id="@+id/field"
/>

我想设置一个自定义命令,这样,当有人点击了完成/转到按钮在屏幕键盘上点击一个按钮或者只是运行由该按钮运行的方法。我觉得这是与IME选择,但我还没有能够弄清楚他们是如何工作的。在此先感谢您的帮助!

I want to set a custom command so that when somebody clicks on the Done/Go button on the onscreen keyboard a button is clicked or just run the methods that are run by the button. I think this has something to do with ime options but I havent been able to figure out how they work. Thanks in advance for any help!

推荐答案

您想要的Andr​​oid的组合:imeOptions和setOnEditorActionListener

You want a combination of android:imeOptions and setOnEditorActionListener

<EditText android:id="@+id/some_edittext"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:imeOptions="actionSend">
</EditText>


some_edittext.setOnEditorActionListener(new OnEditorActionListener() {
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEND) {
            some_button.performClick();
            return true;
        }
        return false;
    }
});

显然,你应该改变actionSend到你想要的操作,并更新IME_ACTION_SEND水涨船高。

Obviously you should change actionSend to the action you want, and update IME_ACTION_SEND correspondingly.

这篇关于安卓:编辑文本GO按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆