checkbox not get checked according to list values in android

前端 未结 3 509
半阙折子戏
半阙折子戏 2021-01-28 03:27

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

相关标签:
3条回答
  • 2021-01-28 03:36

    You don't need

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

    0 讨论(0)
  • 2021-01-28 03:41

    Try using OR (||) in your if() statement.

    if(a==b  || a==c || b==c)
            {
                //Your action
            }
    

    or Better use switch cases,

    switch(position) {
      case 0:
        ...
        break;
      case 1:
        ...
        break;
      default:
        ...
    
    }
    
    0 讨论(0)
  • 2021-01-28 03:50

    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;
    
            }
        }
    
    0 讨论(0)
提交回复
热议问题