android - 如何使用 imeactionId 的值

标签 android

我尝试将自己的值设置为 imeActionId,然后将其与 onEditorAction 中的 actionId 进行比较。但是方法中的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。 如何使用我定义的 imeActionIdactionId 进行比较。

最佳答案

抱歉回复晚了。仍在发布我的答案以造福他人。实际上,每个 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/

相关文章:

java - 如何使用volley使代码更新数据?

android - IONIC APP - 删除 ion-modal-view 上的顶部栏

android - Firebase 云消息传递设备 ID : multiple user in same app in same device

android - 如何通过android中的特定应用程序分别查找wifi和网络数据使用情况?

android - Robolectric:如何设置希望 Calendar 类返回的时间?

android - 错误 :Execution failed for task ':app:kaptDemoTestingDebugKotlin'

android - 有人可以向我解释这个 `StaleDataException`

android - Android Studio 中的项目无法启动 - 未指定 Activity 类

c# - 设置 Xamarin.Forms - "No resource found that matches the given name..."

java - Media Recorder 在 Android 中启动失败,用于三星 Galaxy s3 的前置摄像头