Justin Macrae Justin Macrae - 6 months ago 25
Java Question

Check Box Will Not Disable When Checked, android studio

Just like the title says, I have done some research and altered my code but still when I run it, it does not disable. Any idea why?

cb_leic.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() {

@Override
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
if(isChecked){
cb_leic.setEnabled(false); // disable checkbox
}
}
} );

Answer
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.link);

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

     cb_leic.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                Toast.makeText(Check.this, " cb_leic", Toast.LENGTH_SHORT)
                        .show();
                 cb_leic.setEnabled(false); // disable checkbox
            }

        }

    });
}
Comments