我有一个定义如下的Edit Text。
<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/Go按钮时,就会单击一个按钮,或者只运行该按钮运行的方法。我认为这与ime选项有关,但我还不能弄清楚它们是如何工作的。提前感谢您的帮助!
发布于 2010-07-19 04:59:47
你想要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。
发布于 2010-07-19 04:13:32
看一下setImeActionLabel
方法(或imeActionLabel
和imeActionId
属性)和setOnEditorActionListener
,以设置一个监听器来响应事件。
https://stackoverflow.com/questions/3276448
复制相似问题