Android 安卓-当触摸外部视图时,如何关闭注入微调器的AlertDialog?

Android 安卓-当触摸外部视图时,如何关闭注入微调器的AlertDialog?,android,dialog,touch,spinner,Android,Dialog,Touch,Spinner,基本上,我想做的是关闭微调器对话框和在这些对话框外单击时创建的自定义对话框。有人知道怎么处理这些吗 dialog.xml,我的微调器的xml,下面的MakeandShowDialogBox函数: dialog.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_w

基本上,我想做的是关闭微调器对话框和在这些对话框外单击时创建的自定义对话框。有人知道怎么处理这些吗

dialog.xml,我的微调器的xml,下面的MakeandShowDialogBox函数:

dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout 
        android:id="@+id/scheduleTable"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        ></TableLayout>

</LinearLayout>

您是否尝试调用此方法
setcanceledontouchout(true)


很好,它应该可以工作。

您是否尝试调用此方法
setcanceledontouchout(true)


好吧,应该可以了。

您只需在对话框中添加此选项即可


myDialogBox.setCancelable(true)

您只需在对话框中添加此选项


myDialogBox.setCancelable(true)

遗憾的是,我无法用视图对象调用这样的方法。所以它的一部分不起作用,微调器一也是个谜。@Mack你试过
myDialogBox
这个吗?只有
cancelable
两种方法都有。遗憾的是,我不能用View对象调用这样的方法。所以它的一部分不起作用,旋转器一也是个谜。@Mack你试过
myDialogBox
这个吗?只有
cancelable
两个都有。旋转器的问题是一样的。。。!!您现在有解决方案吗?旋转器也有同样的问题。。。!!你现在有解决办法吗?
<Spinner
    android:id="@+id/spinList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:entries="@array/strDepartmentNames"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:spinnerMode="dialog"
    android:paddingTop="15dp"
    android:paddingBottom="15dp" />
private void makeAndShowDialogBox() {

    AlertDialog.Builder myDialogBox = new AlertDialog.Builder(this);

    final LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View dialogView = layoutInflater.inflate(R.layout.dialog, null);

    // Set three option buttons
    myDialogBox.setPositiveButton("Close",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                }
            });

    myDialogBox.setView(dialogView);
    myDialogBox.create();
    myDialogBox.show();
}
myDialogBox.setCanceledOnTouchOutside(true);