【问题标题】:Android - How an AlertDialog injected with spinner can be closed when touched outer view?Android - 触摸外部视图时如何关闭注入微调器的 AlertDialog?
【发布时间】:2014-11-16 19:45:25
【问题描述】:

基本上我想做的是关闭 Spinner 的对话框和我在这些框外单击时创建的自定义对话框。有谁知道如何处理这些?

dialog.xml,My Spinner 的 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>

微调器 XML

<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" />

ma​​keAndShowDialogBox

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();
}

【问题讨论】:

  • 微调器的同样问题...!!你现在解决了吗?

标签: android dialog touch spinner


【解决方案1】:

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

myDialogBox.setCancelable(true);

【讨论】:

    【解决方案2】:

    你有没有尝试调用这个方法setCanceledOnTouchOutside(true)

    myDialogBox.setCanceledOnTouchOutside(true);
    

    Afaik 它应该可以工作。

    【讨论】:

    • 遗憾的是,我无法使用视图对象调用这样的方法。所以它不适用于其中的一部分,Spinner 之一也是一个谜。
    • @Mack 你试过myDialogBox这个吗?
    • 只有Cancellable 来自两者。
    猜你喜欢
    • 1970-01-01
    • 2020-05-06
    • 2017-07-04
    • 1970-01-01
    • 2020-04-11
    • 2014-06-25
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    相关资源
    最近更新 更多