android开发分享Android:编辑文本Gobutton

我有一个编辑文本,定义如下。

<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" /> 

我想设置一个自定义的命令,当有人点击屏幕键盘上的Done / Gobutton时,单击一个button或者只是运行button运行的方法。 我认为这与时间选项有关,但我还没有弄清楚它们是如何工作的。 提前感谢任何帮助!

    你想要一个android:imeOptions和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。

    看看setImeActionLabel方法(或imeActionLabelimeActionId属性)和setOnEditorActionListener来设置一个侦听器来响应事件。

    以上就是android开发分享Android:编辑文本Gobutton相关内容,想了解更多android开发(异常处理)及android游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/addevelopment/514239.html

      (0)
      上一篇 2020年11月29日
      下一篇 2020年11月29日

      精彩推荐