java - Android listview first and last item selected on small screen device -
i have problem listview on devices small screen, when click on first item of list , scroll end, see last item selected color of first item.
part of adapter code :
public static class viewholder { textview mitemtitleview; } @override public view getview(final int position, view convertview, viewgroup parent) { viewholder = new viewholder(); if (convertview == null) { convertview = minflater.inflate(this.mlayoutid, parent, false); viewholder.mitemtitleview = (textview) convertview.findviewbyid(r.id.itemtitle); convertview.settag(viewholder); } else { viewholder = (viewholder) convertview.gettag(); } typeface futura_font = typeface.createfromasset(getcontext().getassets(), "fonts/futura.ttf"); viewholder.mradionameview.settypeface(futura_font); viewholder.mitemtitleview.settext("something"); return convertview; }
device test : samsung galaxy s2 on android 2.3.7.
screenshots :
- top of list , first item selected : http://i.stack.imgur.com/cldze.jpg
- after scroll, see last item selected haven't clicked on : http://i.stack.imgur.com/mu0ak.jpg
i had exact problem week ago. code use highlight item has in getview function , not outside of it, because getview called everytime scroll.
add so:
@override public view getview(final int position, view convertview, viewgroup parent) { viewholder = new viewholder(); if (convertview == null) { convertview = minflater.inflate(this.mlayoutid, parent, false); viewholder.mitemtitleview = (textview) convertview.findviewbyid(r.id.itemtitle); convertview.settag(viewholder); } else { viewholder = (viewholder) convertview.gettag(); } typeface futura_font = typeface.createfromasset(getcontext().getassets(), "fonts/futura.ttf"); viewholder.mradionameview.settypeface(futura_font); viewholder.mitemtitleview.settext("something"); if(getitematposition(position).ishighlighted){ //add hightlighting item did outside of getview //in app, highlighting item makes text red //so should put code makes text red here } return convertview; }
this work if every item saved boolean higlighted variable.
after add this, getview not mistakenly add highlighting last item.
Comments
Post a Comment