【问题标题】:Show the value of an item at a position in a Material Dialog在材质对话框中的某个位置显示项目的值
【发布时间】:2017-12-20 15:17:53
【问题描述】:

我有一个数组字符串列表,我在材质对话框中填充值。当我单击对话框中的某个项目时,我想在该位置获取该项目并将值设置为 TextView。不幸的是,无论我选择哪个项目,我仍然将最后一个值设置为 TextView。

我的代码:

new MaterialDialog.Builder(DetailProfileActivity.this)
    .title(R.string.id_types_title)
    .items(set)
    .itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {
        @Override
        public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
            idType = which;
            switch (idType){
                case 0:
                    txtIdType.setText("Voters");
                case 1:
                    txtIdType.setText("Passport");
                case 2:
                    txtIdType.setText("DriversLicense");
            }

            return true;
        }
    })
    .positiveText(R.string.choose)
    .show();

【问题讨论】:

  • @R2R 我的问题是即使我选择不同的选项,我也只能将值“DriversLicense”设置为我的 TextView。

标签: android dialog android-dialog


【解决方案1】:

试试这个onSelection(),给出可以直接使用的字符串结果

new MaterialDialog.Builder(DetailProfileActivity.this)
            .title(R.string.id_types_title)
            .items(set)
            .itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    txtIdType.setText(text);
                    return true;
                }
            })
            .positiveText(R.string.choose)
            .show();
}

【讨论】:

  • 感谢您的回答。不知道我在想什么。
猜你喜欢
  • 2020-02-23
  • 2020-02-22
  • 2017-12-19
  • 1970-01-01
  • 2022-10-24
  • 1970-01-01
  • 1970-01-01
  • 2017-06-14
  • 2017-10-07
相关资源
最近更新 更多