How to set the background of the marked items in the list in multiple selection mode in android

I have a ListActivity

 public class MyActivity extends ListActivity{ protected void onCreate(Bundle savedstate){ super.onCreate(savedstate); getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { Log.i("xxx", "onPrepareActionMode"); return false; } public void onDestroyActionMode(ActionMode mode) { // TODO Auto-generated method stub } public boolean onCreateActionMode(ActionMode mode, Menu menu) { // TODO Auto-generated method stub return true; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { // TODO Auto-generated method stub return false; } public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { Log.i("xxx", "pos: "+position+", checked: "+checked); mode.setTitle(getListView().getCheckedItemCount()+" checked"); } }); } } 

Here I see that the elements are checked, but the background of the checked elements does not change. I know a way to do this, set the CustomAdapter and getView() background of the checked views. But I believe that there is a much simpler way to handle this. Could you tell me if it is anyway to achieve this?

Screenshot Attachment

+4
source share
1 answer

Ok, I got the answer by looking at the source code of another application that does this. Set a statistics item that can be used as the background for the list item. In the state_activated = true selector, set the background image.

+12
source

Source: https://habr.com/ru/post/1447210/


All Articles