Hi I am new to android programming world and I am stuck with this issue where I want to have one common onClickListener or onCheckChangedListener for all multiple checkBox in the view.
In most of the forums I have gone through they suggest to implement OnClickListener to each of the checkBox and I felt that is not a good idea and feel its a unnecessary overhead. So the requirement is I have days related checkBoxes, each day representing Sunday to Saturday along with EveryDay. I need to deselect all days checked when Everyday is checked and deselect EveryDay checkBox when any other day is Checked.
Below code I tried but control never reaches inside onClickListener.
public class AddEditGroupActivity extends Activity
implements View.OnClickListener {
public void onClick(View v) {
if(v.getId() == R.id.addedit_restrict_byeveryday) {
if(((CheckBox)v).isChecked()) {
((CheckBox) findViewById(R.id.addedit_restrict_bysunday)).setChecked(false);
((CheckBox) findViewById(R.id.addedit_restrict_bymonday)).setChecked(false);
((CheckBox) findViewById(R.id.addedit_restrict_bytuesday)).setChecked(false);
((CheckBox) findViewById(R.id.addedit_restrict_bywednesday)).setChecked(false);
((CheckBox) findViewById(R.id.addedit_restrict_bythursday)).setChecked(false);
((CheckBox) findViewById(R.id.addedit_restrict_byfriday)).setChecked(false);
((CheckBox) findViewById(R.id.addedit_restrict_bysaturday)).setChecked(false);
}
} else if(v.getId() != R.id.addedit_restrict_byeveryday) {
if(((CheckBox)v).isChecked()) {
((CheckBox) findViewById(R.id.addedit_restrict_byeveryday)).setChecked(false);
}
}
}
}
Please suggest what is the way forward to achieve this task.
Aucun commentaire:
Enregistrer un commentaire