android - How to update image of ImageView in Custom ListView -
i trying click on imageview of custom listview , want change image on onclick event. able click on success other operation images not reflected of imageview.
here code reference.
public class reminderadapter extends baseadapter { private activity activity; private static layoutinflater inflater=null; imageview firststar,secondstar,thirdstar,fourthstar,fifthstar; public reminderadapter(activity a, arraylist<hashmap<string, string>> d) { activity = a; data=d; inflater = (layoutinflater)activity.getsystemservice(context.layout_inflater_service); facebold = typeface.createfromasset(activity.getassets(), "fonts/eau_sans_bold.otf"); facenormal = typeface.createfromasset(activity.getassets(), "fonts/eau_sans_book.otf"); } public int getcount() { return data.size(); } public object getitem(int position) { return position; } public long getitemid(int position) { return position; } public view getview(int position, view convertview, viewgroup parent) { view vi=convertview; if(activity instanceof searchdishoom) { if(convertview==null) vi = inflater.inflate(r.layout.remind_dish_list_row, null); firststar = (imageview)vi.findviewbyid(r.id.hotellistfirststar); secondstar = (imageview)vi.findviewbyid(r.id.hotellistsecondstar); thirdstar = (imageview)vi.findviewbyid(r.id.hotellistthirdstar); fourthstar = (imageview)vi.findviewbyid(r.id.hotellistfourthstar); fifthstar = (imageview)vi.findviewbyid(r.id.hotellistfifthstar); firststar.setfocusable(false); secondstar.setfocusable(false); thirdstar.setfocusable(false); fourthstar.setfocusable(false); fifthstar.setfocusable(false); firststar.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { setstar(1); } }); secondstar.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { //reminderlist.clear(); setstar(2); } }); thirdstar.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { setstar(3); } }); fourthstar.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { setstar(4); } }); fifthstar.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { setstar(5); } }); } return vi; } public void setstar(int btnnumber) { if (btnnumber == 1) { firststar.setimageresource(r.drawable.rated); secondstar.setimageresource(r.drawable.unrated); thirdstar.setimageresource(r.drawable.unrated); fourthstar.setimageresource(r.drawable.unrated); fifthstar.setimageresource(r.drawable.unrated); //postrating(1); } if (btnnumber == 2) { firststar.setimageresource(r.drawable.rated); secondstar.setimageresource(r.drawable.rated); thirdstar.setimageresource(r.drawable.unrated); fourthstar.setimageresource(r.drawable.unrated); fifthstar.setimageresource(r.drawable.unrated); //postrating(2); } if (btnnumber == 3) { firststar.setimageresource(r.drawable.rated); secondstar.setimageresource(r.drawable.rated); thirdstar.setimageresource(r.drawable.rated); fourthstar.setimageresource(r.drawable.unrated); fifthstar.setimageresource(r.drawable.unrated); //postrating(3); } if (btnnumber == 4) { firststar.setimageresource(r.drawable.rated); secondstar.setimageresource(r.drawable.rated); thirdstar.setimageresource(r.drawable.rated); fourthstar.setimageresource(r.drawable.rated); fifthstar.setimageresource(r.drawable.unrated); //postrating(4); } if (btnnumber == 5) { firststar.setimageresource(r.drawable.rated); secondstar.setimageresource(r.drawable.rated); thirdstar.setimageresource(r.drawable.rated); fourthstar.setimageresource(r.drawable.rated); fifthstar.setimageresource(r.drawable.rated); //postrating(5); } }
i don't understand happening. please give me reference or hint.
in advance.
try this
firststar.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { setstar(1); listadapter.notifydatasetchanged(); } });
Comments
Post a Comment