ListView item won't stay “selected”

后端 未结 10 1295
暗喜
暗喜 2020-12-10 05:50

I want to change the background of a listview item when the user clicks it. Kind of like the Honeycomb settings page (Although I\'m not dealing with just settings so I\'m no

10条回答
  •  天涯浪人
    2020-12-10 06:52

    When you release your finger from the cell it no longer registers as pressed. What you are going to want to do is actually change the background of the individual row when a users selects is. This means implementing an onItemClick or onItemTouch and flagging the adapter to redraw the row with the new background. If you are already using a custom list adapter you can just implement a check against a boolean in your getView() method. You will also need to keep track which rows are 'selected' and which are not.

    pseudocode:

       public View getView(int pos, View convertView, ViewGroup parent) {
          if(isChecked[pos]) //set background to checked color
       }
    

提交回复
热议问题