【问题标题】:Edittext : Attempted to finish an input event but the input event receiver has already been disposedEdittext:尝试完成输入事件,但输入事件接收器已被释放
【发布时间】:2017-08-10 10:46:41
【问题描述】:

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.file

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:尝试完成输入事件,但输入 事件接收器已被释放

【问题讨论】:

    标签: java android input dialog


    【解决方案1】:

    由于您将在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;
                }
            });
    

    【讨论】:

      猜你喜欢
      • 2016-03-02
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 2012-03-30
      • 2017-08-26
      • 1970-01-01
      相关资源
      最近更新 更多