androidlistviewcheckboxcheckedtextview

Android - Custom CheckedTextView in listView doesn't get checked on click/disables SINGLE_CHOICE mode


<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.

((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).

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?


Solution

  • 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.