Listview Adapter selected row background android -


i changing listviewadapter row selected item dynamically. in adapter default selecteditem -1.

public static int selecteditem = -1; // no item selected default 

and method highlightitem called in adapter getview method.

public view getview(final int position, view convertview, viewgroup parent) {         view vi = convertview;         if (convertview == null) {             vi = inflater.inflate(r.layout.catalogue_row, null);             holder = new viewholder();  highlightitem(selecteditem,position,vi); 

and here highlightitem method.

private static void highlightitem(int selecteditem,int position, view result) {      system.out.println("selected item "+selecteditem);     if(position == selecteditem) {          // can define own color of selected item here         viewholder.lycataloguerow.setbackgroundcolor(color.parsecolor(sharepreferencecontroller.getlistviwhightlightcolor()));      } else {          // can define own default selector here         viewholder.lycataloguerow.setbackgroundcolor(color.parsecolor(sharepreferencecontroller.getlistviwbackgroundcolor()));      } } 

when click on listview item

private onitemclicklistener itemlistener = new onitemclicklistener(){  @override public void onitemclick(adapterview<?> parent, view view, int position,long id) {     // todo auto-generated method stub      int item_position = position -1;      system.out.println("selecteditemposition "+item_position);      catalogueefficientadapter.selecteditem=item_position;      catalogueefficientadapter.notifydatasetchanged();   } 

};

my arraylist contains 3 items. when click on third item being highlighted. if click on second element second element should highlighted third row being hightlighted. how select , hightlight selected item only

update problem highlightitem not updated.

public view getview(final int position, view convertview, viewgroup parent) {         view vi = convertview;         if (convertview == null) {             vi = inflater.inflate(r.layout.catalogue_row, null);      if(position == selecteditem) {          // can define own color of selected item here         vi.setbackgroundcolor(color.parsecolor(sharepreferencecontroller.getlistviwhightlightcolor()));      } else {          // can define own default selector here         vi.setbackgroundcolor(color.parsecolor(sharepreferencecontroller.getlistviwbackgroundcolor()));      } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -