【问题标题】:How to create custom Dialogbox with scrollable items in Android? [closed]如何在 Android 中创建带有可滚动项目的自定义对话框? [关闭]
【发布时间】:2016-03-29 09:25:10
【问题描述】:

我想创建如下图所示的对话框。当我单击该项目时,它不会去任何地方,直到我单击“确定”。

【问题讨论】:

    标签: android material-design dialog


    【解决方案1】:

    试试下面的代码:

    从资源中获取数组(你可以使用arraylist或任何数组)

    final String[] mTestArray = getResources().getStringArray(R.array.hours_array);
    

    用于警告对话框

    new AlertDialog.Builder(MainActivity.this)
                                .setTitle(getString(R.string.app_name))
                                .setSingleChoiceItems(mTestArray, 0, null)
                                .setPositiveButton(R.string.txt_ok, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int whichButton) {
                                        int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
    
                                    }
                                })
                                .setNegativeButton(R.string.txt_cancel, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        // do nothing
    
                                    }
                                })
                                .show();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-22
      • 2011-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-20
      相关资源
      最近更新 更多