Change ListView Item Background on click - Android

前端 未结 3 773
陌清茗
陌清茗 2020-12-20 09:24

I\'ve prepared a custom listview using BaseAdapter. Now I want to change color of selected item of listview on click event. And multiple items should be selected. Here I am

3条回答
  •  鱼传尺愫
    2020-12-20 09:47

    Since you've implemented BaseAdapter, which has a core method called getView, you can easily store the states of items in BaseAdapter. For example, you can use List to store the states.

    Then, a listener of the ListView should be implemented, as described in http://developer.android.com/reference/android/widget/AdapterView.html#setOnClickListener(android.view.View.OnClickListener). The documentation of OnItemClickListener is here, http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html, through which you can get the positions of the clicks.

    Finally, change the state of the items after on-click events, and call notifyDataSetChanged() in adapter to notify that the data has been changed and you'll see the updated selected items.

提交回复
热议问题