java - 编辑文本 : Attempted to finish an input event but the input event receiver has already been disposed

标签 java android input dialog

XML.xml

<android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="16dp"
                    android:layout_marginLeft="16dp"
                    app:hintTextAppearance="@style/WhiteTextInputLayout"
                    android:layout_marginTop="8dp"
                    android:id="@+id/txDept"
                    android:textColorHint="#FFF"
                    android:layout_marginBottom="8dp">
                    <EditText
                        android:id="@+id/input_department"
                        android:layout_width="match_parent"
                        android:layout_marginRight="16dp"
                        android:layout_marginLeft="16dp"
                        android:layout_height="wrap_content"
                        android:textColor="#FFF"
                        android:editable="false"
                        android:drawableRight="@drawable/ic_department"
                        android:inputType="text"
                        android:hint="Department"/>
                </android.support.design.widget.TextInputLayout>

Java.文件

etDepartment.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                chooseDepartment();
                return true;
            }
        });

void chooseDepartment(){

        final CharSequence[] items = {AUTO,CIVIL,CSC,EEE,ECE,EIE,ETE,IT,MBA,MCA,MECH};
        final AlertDialog.Builder builder=new AlertDialog.Builder(SignUp.this);
        builder.setTitle("Choose your Department");
        builder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                etDepartment.setText(items[which]);
                dialog.dismiss();
            }
        });
        builder.show();

    }

当用户单击该列表对话框中显示的项目时..Edittext 将设置该文本。

但现在单击无法关闭对话框。只有单击两三次后,对话框才会关闭。

我在 logcat 中看到的错误:

W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed

最佳答案

由于您将在 OnTouchListener 中执行多个操作,因此此对话框会多次打开,因此请尝试仅对 MotionEvent.ACTION_UP 执行操作,

试试这个,

etDepartment.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if(motionEvent.getAction() == MotionEvent.ACTION_UP) {
                    chooseDepartment();
                }
                return true;
            }
        });

关于java - 编辑文本 : Attempted to finish an input event but the input event receiver has already been disposed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45611575/

相关文章:

java - 需要帮助显示 Web 服务的 SOAP 请求的返回

java - 新手需要帮助 : Database login and user management schema and Dealing with jframe and jdialog form Netbeans 8 Java and mysql

java - 将 Google map 坐标转换为像素

Android - 分屏时的 ActionBar(列表/详细信息)

android - 尝试在 AdMob 中创建 Android 应用程序时,我应该为 "Android Package URL"输入什么?

java - 扫描仪输入阵列

java - 更改 GWT 客户端上的文件输入元素

java - java中创建单词的高效算法

java - LWJGL Keyboard.isKeyDown 方法是否与更新相关?

android - 工具栏上的溢出按钮更改颜色