-
When I use the layout from :
android.R.layout.simple_list_item_single_choiceas 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.
- If I implement an
onClickListenerlike this in the listadapter:
((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).
- If I implement the
setOnItemClickListenerin 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
idof theCheckedTextViewsame as the one used inandroid.R.layout.simple_list_item_single_choiceworked for me. The id is@android:id/text1.