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

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

visual studio - TFS will not accept changes I've made to a Java project -