Search code examples
androidandroid-listviewlistviewitem

Keeping the color of list item after click


Is there any way to keep the color of listview item after it is clicked. the color of item should remain either or not the activty switches .

Just like the honeycomb versions list view ,we can show an fragment with keeping the color of list item


Solution

  • You can do this by

    lv.setSelection(position);
    

    And For set Color of selected item

    lv= (ListView) findViewById(R.id.list);
    lv.setSelector( R.drawable.listselector);
    

    or else you can use property in XML as

    android:listSelector="#00000000"