Android listview setOnItemClickListener change image backgound by position by switch -
Android listview setOnItemClickListener change image backgound by position by switch -
i working on baseadapter
. wrote code can show images , text in listview
baseadapter
. want alter images , text background position.
this baseadapter
code
public class slidemenuadapter extends baseadapter { private context mcontext; private final string[] menu_items_id; private final int[] imageid; textview textview; imageview imageview; private static layoutinflater inflater = null; public slidemenuadapter(context context, string[] names, int[] imageid) { mcontext = context; this.imageid = imageid; this.menu_items_id = names; inflater = (layoutinflater) mcontext .getsystemservice(context.layout_inflater_service); } @override public int getcount() { homecoming imageid.length; } @override public object getitem(int position) { homecoming null; } @override public long getitemid(int position) { homecoming 0; } @suppresslint("viewholder") @override public view getview(int position, view convertview, viewgroup parent) { view grid; grid = new view(mcontext); grid = inflater.inflate(r.layout.azercell_slidemenu_adaper, null); textview = (textview) grid.findviewbyid(r.id.desc); imageview = (imageview) grid.findviewbyid(r.id.photo); textview.settext(menu_items_id[position]); imageview.setimageresource(imageid[position]); homecoming grid; } }
and listview listener code
listview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { textview textview1 = (textview) parent.findviewbyid(r.id.desc); imageview imageview=(imageview)parent.findviewbyid(r.id.photo); switch (position) { case 0: textview1.settextcolor(color.parsecolor("#8f332a")); imageview.setimageresource(menu_imagesover[position]); break; case 1: textview1.settextcolor(color.parsecolor("#ffffff")); imageview.setimageresource(menu_imagesover[position]); break; default: break; } } }); int[] menu_imagesover = { r.drawable.schedule_ove, r.drawable.about_over, r.drawable.booking_over };
when click in listview can alter first item 's images , text background.how can write code can alter each item position?
try phone call invalidate
method refresh listview
:
switch (position) { case 0: textview1.settextcolor(color.parsecolor("#8f332a")); imageview.setimageresource(menu_imagesover[position]); break; case 1: textview1.settextcolor(color.parsecolor("#ffffff")); imageview.setimageresource(menu_imagesover[position]); break; default: break; } invalidate(); //add here
or if not working, seek phone call invalidateviews
instead of invalidate
.
and think theres fishy switch (position)
, doesnt means code work if 1st , 2nd row clicked?
android android-listview baseadapter onitemclicklistener
Comments
Post a Comment