复选框未根据Android中的列表值进行检查 [英] checkbox not get checked according to list values in android

查看:80
本文介绍了复选框未根据Android中的列表值进行检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我的英语不好,
我个别地将数组列表值添加到复选框. (实际上,这些是来自活动的工作日).但问题是复选框仅将第一个位置值设置为复选框.请让我知道我的代码有什么问题.

Sorry for my bad English,
I am individually getting array list value to the checkboxes. (Actually, these are the weekdays that are coming from the activity). but the problem is checkbox only set the first position value to checkbox. Please let me know what's wrong in my code.

下面是代码段

说这是列表值:

[周一,周二,周日]

这是我通过列表的课程

for (int i = 0; i < myList.size(); i++) {

            switch (myList.get(i)){

                case "Monday":
                    cbMon.setChecked(true);
                    break;

                case "Tuesday" :
                    cbTue.setChecked(true);
                    break;

                case "Wednesday":
                    cbWed.setChecked(true);
                    break;

                case "Thursday":
                    cbThurs.setChecked(true);
                    break;

                case "Friday":
                    cbFri.setChecked(true);
                    break;

                case "Saturday":
                    cbSat.setChecked(true);
                    break;

                case "Sunday":
                    cbSun.setChecked(true);
                    break;

                default:

                    break;

            }

推荐答案

使用此结构,无需以硬编码方式进行操作

use this structure no need to do it in hardcode way

for (int i = 0; i < myList.size(); i++) {

        switch (myList.get(i)){

            case "Monday":
                cbMon.setChecked(true);
                break;

            case "Tuesday" :
                cbTue.setChecked(true);
                break;

            case "Sunday":
                cbSun.setChecked(true);
                break;

            default:break;

        }
    }

这篇关于复选框未根据Android中的列表值进行检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆