Switch statement just returning the last case

前端 未结 4 824
[愿得一人]
[愿得一人] 2021-01-24 00:52

Switch statment fix: The switch statement is only returning the last case i.e case 4, \"#0R0dfdf0FF\". how can i fix this so the text view shows the the one cli

4条回答
  •  一生所求
    2021-01-24 01:35

    You need the break; after all cases except for the last one or else it'll fall through case by case

     switch (which){
            case 0:
                mColor.setText("#000000");
                break;        
            case 1:
                mColor.setText("#0000FF");
                break;        
            case 2:
                mColor.setText("#0R00FF");
                break; 
            case 3:
                mColor.setText("#0R00dsdFF");
                break; 
            case 4:
                mColor.setText("#0R0dfdf0FF");
            default:  
                break; 
            }
    

提交回复
热议问题