Is there a way to have multiple CheckedTextView
in some sort of group like RadioGroup
? So only one CheckedTextView
would be checked at the same time.
If this is not possible as CheckedTextView
is a child of TextView
, what is the most memory efficient way to code logic that only one CheckedTextView
can be checked in the group of 5 other CheckedTextViews
?
It does not look memory efficient that each time one CheckedTextView
is pressed, I check for the check state of all others and change it accordingly.
I managed to do it with CheckedTextView
to behave as part of some group (e.g. only one CheckedTextView
can be selected at a time).
//pass view which fired onClick event
//pass an array or other container of checkedTextViews (optional)
void setCheckedState(View v, CheckedTextView[] whichCheckedViews) {
CheckedTextView temp = (CheckedTextView) v;
//first uncheck all views in the arraw
for (CheckedTextView item : whichCheckedViews)
item.setChecked(false);
//detect which checkedTextView initiated onClick event
switch (v.getId()) {
case R.id.checkedTextView_1:
case R.id.checkedTextView_2:
case R.id.checkedTextView_3:
case R.id.checkedTextView_N:
temp.setChecked(true);
break;
default:
break;
}
}
And this works like a charm.
NOTE: I did not check memory consumption since I have only 5 views. I also did not check execution time since on all test devices it runs without a glitch.