Selecting/highlighting multiple items in listview with custom adapter - Android

為{幸葍}努か 提交于 2019-12-05 03:36:26
S.D.
  1. The root View of each item you will display in list must implement Checkable. When implementing this interface also update the drawable state of View. See this answer for how to do that.

  2. Set a <selector> drawable as background for this root View. Which different color/drawables for checked state and normal states.

  3. Set ListView's choice mode to single choice or multi-choice.

  4. In list adapter, provide item views with above created View as parent layout.

Now, ListView will take care of setting checked/unchecked state on its item views. Also you can call getCheckedItemIds() or getCheckedItemPositions() on ListView to get currently selected items.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!