我试图把我自己的价值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"/>
Run Code Online (Sandbox Code Playgroud)
以下是我的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;
}
});
Run Code Online (Sandbox Code Playgroud)
该actionId来了,不论在XML值的每一次为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;
}
});
Run Code Online (Sandbox Code Playgroud)
有关更多信息,您可以参考此LINK。希望你觉得这个答案有用。
实际上,Android 只识别影响软键盘外观的特定操作(例如 DONE 按钮的存在)。此处列出了所有此类操作,并且都没有代码 666。:)
您需要自定义操作来做什么?想知道它从哪里来吗?然后只需检查视图 id:
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (v.getId() == R.id.editText2) {
// Whatever ...
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
这肯定会起作用!
| 归档时间: |
|
| 查看次数: |
12405 次 |
| 最近记录: |