解除AlertDialog会发出警告尝试完成输入事件但输入事件接收器已被处理掉

时间:2017-07-24 04:27:01

标签: c# android xamarin mvvmcross alertdialog

我有一个带按钮的视图,点击按钮我打开一个警报对话框。我正在使用以下代码创建

    List<String> data = new List<string> { "Hello1", "Hello2", "Hello3", "Hello4" };

    void ChangeTubeButton_Click(object sender, EventArgs e)
    {
        AlertDialog.Builder builder;
        builder = new AlertDialog.Builder(Context);
        builder.SetTitle("Select Tube").SetItems(data.ToArray(), RowSelected);
        AlertDialog alert = builder.Create();
        alert.Show();
    }

    void RowSelected(object senderObject, DialogClickEventArgs eventArgs)
    {
        if (eventArgs.Which >= 0 && eventArgs.Which < data.Count)
        {
            String selectedHello = data.ElementAt(eventArgs.Which);
        }
    }

警报正确显示在UI上,并且能够正确选择行。只是当我在屏幕上点击外面时。警报解除,但在Logcat中发出警告。

[InputEventReceiver] Attempted to finish an input event but the input event receiver has already been disposed.
[ViewRootImpl[NavigationView]] Dropping event due to root view being removed: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=133.8952, y[0]=-190.78308, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=88925144, downTime=88925129, deviceId=1, source=0x1002 }
[InputEventReceiver] Attempted to finish an input event but the input event receiver has already been disposed.

我应该关注这个警告吗? 我想保持我的日志窗口清洁。如果有人可以提供有关警告的帮助。

1 个答案:

答案 0 :(得分:2)

这与您的代码无关。

当您在屏幕上点击外部时,此ACTION_DOWN事件将排队到应用的消息队列。然后通过AlerDialog课程将其发送到您的ViewPostImeInputStage课程,最后ViewPostImeInputStage将此输入事件发送给AlerDialog的{​​{1}}听众。

由于onTouchEvent内没有发生这种情况,您的AlertDialog会调用AlerDialog方法:

dismiss()

public boolean onTouchEvent(MotionEvent event) { if (mCancelable && mShowing && mWindow.shouldCloseOnTouch(mContext, event)) { cancel();//This will call dismiss() method. return true; } return false; } 首先尝试关闭Dissmiss()AlertDialog致电AlertDialog::onDetachedWindow

然后WindowInputEventReceiver::dispose()致电ViewPostImeInputStage完成该WindowInputEventReceiver::finishInputEvent事件。但是ACTION_DOWN r实例已经处理好,因此会抛出警告消息。

当您创建WindowInputEventReceive时,它会与AlertDialog相关联,WindowManagerViewRootImplWindowManager之间的桥梁(它与您的AlertDialog的关系)像这样:DecorView - &gt;活动 - &gt;你的AlertDialog)。你可以在DecorView源代码中找到它:

AlerDialog

以下动作事件“ACTION_MOVE”无法传递给public AlertDialog create() { final AlertDialog dialog = new AlertDialog(P.mContext, mTheme, false); P.apply(dialog.mAlert); dialog.setCancelable(P.mCancelable); if (P.mCancelable) { dialog.setCanceledOnTouchOutside(true); } dialog.setOnCancelListener(P.mOnCancelListener); if (P.mOnKeyListener != null) { dialog.setOnKeyListener(P.mOnKeyListener); } return dialog; } Dialog(Context context, int theme, boolean createContextWrapper) { mContext = createContextWrapper ? new ContextThemeWrapper(context, theme) : context; mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); Window w = PolicyManager.makeNewWindow(mContext); mWindow = w; w.setCallback(this); w.setWindowManager(mWindowManager, null, null); w.setGravity(Gravity.CENTER); mUiThread = Thread.currentThread(); mListenersHandler = new ListenersHandler(this); } ,因为它已被处理,因此AlertDialogViewRootImpl并发出警告消息。