CheckedTextView not able to check the items

221 views Asked by At

I am working on list view with CheckedTextView,

Below is my code:

RelativeLayout parentMostLayout = new RelativeLayout(activity);
    parentMostLayout.setLayoutParams(new AbsListView.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
        RelativeLayout.LayoutParams.WRAP_CONTENT));

CheckedTextView checkedTextView = new CheckedTextView(activity);
int[] attrs = { android.R.attr.listChoiceIndicatorMultiple };
    TypedArray ta = activity.getTheme().obtainStyledAttributes(attrs);
    Drawable indicator = ta.getDrawable(0);
    checkedTextView.setCheckMarkDrawable(indicator);
    ta.recycle();
parentMostLayout.addView(checkedTextView, checkedTextViewlLayoutParams);

When i try to check that item its not marking the item that i am trying to select, what might be the issue here?

EDIT

ListView listView = new ListView(activity);
listView.setCacheColorHint(Color.TRANSPARENT);
    listView.setDivider(new ColorDrawable(0x99000000));
    listView.setDividerHeight(1);
listView.setSelector(R.drawable.listselector);
RelativeLayout.LayoutParams listViewParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
        RelativeLayout.LayoutParams.MATCH_PARENT);
listViewParams.addRule(RelativeLayout.ABOVE, footerBar.getId());
1

There are 1 answers

0
InnocentKiller On

Add below line.

//  for single check
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

// for multiple check
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

where replace mListView with your Listview object name.