Nothing happens when CheckBox is checked
-
I created program where when user checks checkbox edit text is enabled, but when I check any of checkboxes nothing happens!!!
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);editText2 = (EditText) findViewById(R.id.editText\_symbols); editText3 = (EditText) findViewById(R.id.editText\_numbers); editText4 = (EditText) findViewById(R.id.editText\_lowercase); editText5 = (EditText) findViewById(R.id.editText\_uppercase); editText2.setEnabled(false); editText3.setEnabled(false); editText4.setEnabled(false); editText5.setEnabled(false); } public void checkCheckBox(View view) { boolean checked = (((CheckBox)view).isChecked()); switch (view.getId()) { case R.id.checkBox\_uppercase: if(checked) editText2.setEnabled(true); else editText2.setEnabled(false); break; case R.id.checkBox\_lowercase: if(checked) editText3.setEnabled(true); else editText3.setEnabled(false); break; case R.id.checkBox\_numbers: if(checked) editText4.setEnabled(true); else editText4.setEnabled(false); break; case R.id.checkBox\_symbols: if(checked) editText5.setEnabled(true); else editText5.setEnabled(false); break; } }
-
I created program where when user checks checkbox edit text is enabled, but when I check any of checkboxes nothing happens!!!
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);editText2 = (EditText) findViewById(R.id.editText\_symbols); editText3 = (EditText) findViewById(R.id.editText\_numbers); editText4 = (EditText) findViewById(R.id.editText\_lowercase); editText5 = (EditText) findViewById(R.id.editText\_uppercase); editText2.setEnabled(false); editText3.setEnabled(false); editText4.setEnabled(false); editText5.setEnabled(false); } public void checkCheckBox(View view) { boolean checked = (((CheckBox)view).isChecked()); switch (view.getId()) { case R.id.checkBox\_uppercase: if(checked) editText2.setEnabled(true); else editText2.setEnabled(false); break; case R.id.checkBox\_lowercase: if(checked) editText3.setEnabled(true); else editText3.setEnabled(false); break; case R.id.checkBox\_numbers: if(checked) editText4.setEnabled(true); else editText4.setEnabled(false); break; case R.id.checkBox\_symbols: if(checked) editText5.setEnabled(true); else editText5.setEnabled(false); break; } }
-
I created program where when user checks checkbox edit text is enabled, but when I check any of checkboxes nothing happens!!!
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);editText2 = (EditText) findViewById(R.id.editText\_symbols); editText3 = (EditText) findViewById(R.id.editText\_numbers); editText4 = (EditText) findViewById(R.id.editText\_lowercase); editText5 = (EditText) findViewById(R.id.editText\_uppercase); editText2.setEnabled(false); editText3.setEnabled(false); editText4.setEnabled(false); editText5.setEnabled(false); } public void checkCheckBox(View view) { boolean checked = (((CheckBox)view).isChecked()); switch (view.getId()) { case R.id.checkBox\_uppercase: if(checked) editText2.setEnabled(true); else editText2.setEnabled(false); break; case R.id.checkBox\_lowercase: if(checked) editText3.setEnabled(true); else editText3.setEnabled(false); break; case R.id.checkBox\_numbers: if(checked) editText4.setEnabled(true); else editText4.setEnabled(false); break; case R.id.checkBox\_symbols: if(checked) editText5.setEnabled(true); else editText5.setEnabled(false); break; } }
Try this
((CheckBox)view).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean checked) { switch (view.getId()) { case R.id.checkBox\_uppercase: if(checked) editText2.setEnabled(true); else editText2.setEnabled(false); break; case R.id.checkBox\_lowercase: if(checked) editText3.setEnabled(true); else editText3.setEnabled(false); break; case R.id.checkBox\_numbers: if(checked) editText4.setEnabled(true); else editText4.setEnabled(false); break; case R.id.checkBox\_symbols: if(checked) editText5.setEnabled(true); else editText5.setEnabled(false); break; } } });
Late but hope this helps!