When I use the layout from : android.R.layout.simple_list_item_single_choice
as list item, the checkbox gets checked on click and everything is fine.
However when I use the layout :
<CheckedTextView android:id="@+id/choice_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CheckedTextView"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:textSize="@dimen/text_size_medium"/>
The checkbox won't get toggled.
onClickListener
like this in the list adapter
:((CheckedTextView) convertView.findViewById(R.id.dp_quiz_answer_choice_item)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
((CheckedTextView) v).toggle();
}
});
SINGLE_CHOICE
mode gets disabled(any number of check boxes can be enabled).
setOnItemClickListener
in the list view the checkbox won't get toggled.mChoiceList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int item,
long id) {
mChoiceList.setItemChecked(item, true);
}
});
Is there any way to have a custom layout for SINGLE_CHOICE
mode ListView
?
Its kind of weird for me, after many other experiments I learnt that having the id
of the CheckedTextView
same as the one used in android.R.layout.simple_list_item_single_choice
worked for me. The id is @android:id/text1
.