0

I have a multi select item listview based on a custom row layout inside a fragment. I would like each checked row to be highlighted.

Problem is when i click a row the checked rows do not stay highlighted but the font color of the text changes. I do not get this issue when using android.R.layout.simple_list_item_1 . Thanks in advance

onCreateView Code

 ...
 listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
 getLoaderManager().initLoader(LOADER, null, this); 
        adapter = new ContactFragmentAdapter(
                getActivity().getApplicationContext(),null,0);
        listView.setAdapter(adapter);

Custom row layout

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <TextView
        android:id="@+id/simple_text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="test"
        />

</LinearLayout>

ListView Code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
 <ListView
        android:id="@+id/contact_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@null"

        />

</LinearLayout>
DeveloperDH
  • 413
  • 5
  • 16
  • Show your ListView xml – Marcus Feb 07 '15 at 19:15
  • Hi Marcus, I have edited the question – DeveloperDH Feb 07 '15 at 20:44
  • You should check this out http://stackoverflow.com/questions/1362602/selecting-multiple-items-in-listview – Marcus Feb 07 '15 at 21:03
  • tried that, unfortunately did not work – DeveloperDH Feb 07 '15 at 22:27
  • Can u try to put android:background="?android:attr/activatedBackgroundIndicator" in the LinearLayout of your custom row? – Ilenca Feb 11 '15 at 16:43
  • Thanks for the update. I have a minimum api of level 8, this requires api level 11. I will investigate further and edit the question as i think maybe the issue is that the custom cursor adapter new view method keeps redrawing the item hence i keep losing the background color change – DeveloperDH Feb 13 '15 at 23:04
  • possible duplicate of [Multiple choice list with custom view?](http://stackoverflow.com/questions/2652109/multiple-choice-list-with-custom-view) – mbelsky Sep 17 '15 at 17:52

0 Answers0