【问题标题】:Can't add multi choice check box to dialog无法将多选复选框添加到对话框
【发布时间】:2015-11-29 00:01:54
【问题描述】:

我正在尝试在我的对话框中添加一个复选框,但我无法做到。它没有出现。这是我的代码:

private void checkAnimationSettings() {

    try {
        ContentResolver cr = activity.getContentResolver();
        float animationDurationScale =
                Settings.Global.getFloat(cr, Settings.Global.ANIMATOR_DURATION_SCALE);
        float windowsAnimationScale =
                Settings.Global.getFloat(cr, Settings.Global.WINDOW_ANIMATION_SCALE);
        float transitionAnimationScale =
                Settings.Global.getFloat(cr, Settings.Global.TRANSITION_ANIMATION_SCALE);

        if (animationDurationScale == 0.0f
                || windowsAnimationScale == 0.0f
                || transitionAnimationScale == 0.0f) {
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
            boolean newerShowAnimationsOffWarning = sp.getBoolean("newerShowAnimationsOffWarning", false);

            if (newerShowAnimationsOffWarning) return;

            CharSequence[] items = new CharSequence[]{"Bir daha gösterme"};
            Builder builder = new Builder(mainActivity);
            builder.setTitle(activity.getString(R.string.animation_settings_warning_title_text));
            builder.setMessage(activity.getString(R.string.animation_settings_warning_text));
            builder.setMultiChoiceItems(items, null, this);
            builder.setPositiveButton("Tamam", null);
            builder.create().show();
        }
    } catch (Settings.SettingNotFoundException e) {
        e.printStackTrace();
    }
}

这里有什么问题?

提前致谢。

【问题讨论】:

  • 这是因为您同时设置了消息和项目。尝试保留其中任何一个,否则使用自定义布局。检查这个stackoverflow.com/a/9127944/3831557
  • @RajenRaiysrela 请添加您的评论作为答案。我会接受的。

标签: android checkbox android-alertdialog


【解决方案1】:

据此answer

我不知道为什么 setMessage 和 setMultiChoiceItems 不能工作 一起。当我删除 setMessage 时,列表显示得很好。

同时设置消息和项目列表将不起作用。

对于 AlertDialog,您可以保留消息或项目列表。

【讨论】:

    猜你喜欢
    • 2012-04-03
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多