0

hello guys, got this code but it has an error.

any ideas? Thanks.

public void ListenerCheckAll() {

        Chbox0 = (CheckBox) findViewById(R.id.checkBox1);

        xAllButton = (Button) findViewById(R.id.button1);


        xAllButton.setOnClickListener(new OnClickListener() {  

            @Override   
            public void onClick(View vx) {

                Chbox0 = (CheckBox) findViewById(R.id.checkBox1);


                 boolean checked = ((CheckBox) vx).isChecked();

                       //this part has the error
                    switch(vx.getId()){
                case R.id.CheckBox01:
                    if (checked){
                     Toast.makeText(ChTxtMainActivity.this,
                      "CheckBox1 is checked", Toast.LENGTH_SHORT).show();
                       edTxt1.setEnabled(false);
                      break;
                    }
                      }  

           }


         });

        }
2
Contributors
3
Replies
9
Views
4 Years
Discussion Span
Last Post by peter_budo
0

hi peter, log cat error actually is quite useless. i run it through the emulator the error message is quite general (not a specific error).

0

Just realised you are using switch statment and validating view ID. This is no longer safe. If you need to do that you should then doing it from if/else

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.