list - Android ListActivity using SimpleAdapter - Highlight selected item -
i´m using simpleadapter in listactivity , want when user select item highlight item. tried extends simpleadapter , override getview() method:
public view getview(int position, view convertview, viewgroup parent) { view view = super.getview(position, convertview, parent); if (position == mitemindex) { convertview.setselected(true); convertview.setpressed(true); convertview.setbackgroundcolor(color.parsecolor("#ff9912")); } return view; }
but solution don´t work properly. set background color more 1 list row. can sameone me?
that's because convertview
being reused , not update selected state both cases (selected / not selected). need call setselected(false)
when not item want selected , reset background color. also, call setpressed
not needed.
you should checkout colorstatelist
allow define colors various states. use built in support single item selection.
Comments
Post a Comment