我试图将自己的值设置为imeActionId
,然后将其与actionId
中的onEditorAction
进行比较。但是该方法中的actionId
重复返回0。
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text|textUri"
android:imeOptions="actionGo"
android:imeActionId="666"
android:imeActionLabel="google"/>
以下是我的
onEditorAction
:et.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// TODO Auto-generated method stub
Log.v("myid iss", "" + actionId);
if(actionId == 666)
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://" + v.getText().toString()));
imm.hideSoftInputFromInputMethod(v.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
startActivity(i);
}
return false;
}
});
每次与XML中的值无关,
actionId
都会变为0。如何使用定义的
imeActionId
与actionId
进行比较。 最佳答案
抱歉回复晚了。仍在发布我的答案以造福他人。实际上,每个imeoptions都有一个unqiueId。为了执行任务,您可以使用以下工作代码。
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_GO) {
//Perform your Actions here.
}
return handled;
}
});
有关更多信息,您可以引用此LINK。希望您觉得这个答案有用。
关于android - 如何使用imeactionId的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24839717/