android - How can i use Button OnClick in Custom ListView with View Holder -
i need help, using viewholder display dynamic arrayadapter.
i have list view .
each row contains ;
title (textview), sub title(textview), progress bar download button (button).i want show progress bar , hide download button when download button clicked. when download button in first row clicked, first progress bar showing 8th progress bar showing too.
this code. doing wrong?
public class tabincomingadaptor extends baseadapter { public static class viewholder { textview title; textview desc; button downloadbutton; progressbar pb; } private arraylist<rowobject> data; private layoutinflater inflater = null; private application ap; // final private activity currentactivity; button progressbutton1; int currentuser; public tabincomingadaptor(activity activity, application application, arraylist<rowobject> gelenfakslar) { // currentactivity = activity; ap = application; info = gelenfakslar; inflater = (layoutinflater) ap .getsystemservice(context.layout_inflater_service); } public int getcount() { homecoming data.size(); } public object getitem(int position) { homecoming position; } public long getitemid(int position) { homecoming position; } public view getview(final int position, view vi, viewgroup parent) { viewholder viewholder; if (vi == null) { vi = inflater.inflate(r.layout.tab_incoming_row, parent, false); viewholder = new viewholder(); viewholder.title = (textview) vi.findviewbyid(r.id.rowtitle); viewholder.desc = (textview) vi.findviewbyid(r.id.rowdesc); viewholder.downloadbutton = (button) vi .findviewbyid(r.id.rowdownloadbutton); viewholder.pb = (progressbar) vi .findviewbyid(r.id.rowdownloadprogress); viewholder.downloadbutton.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { linearlayout vwparentrow = (linearlayout) v.getparent(); v.setvisibility(view.gone); progressbar zxcv = (progressbar) vwparentrow.getchildat(0); zxcv.setvisibility(view.visible); vwparentrow.refreshdrawablestate(); } }); vi.settag(viewholder); } else { viewholder = (viewholder) vi.gettag(); } viewholder.title.settext(data.get(position).getbaslik()); viewholder.desc.settext(data.get(position).gettarih()); homecoming vi; } }
the problem onclicklistener
viewholder.downloadbutton
beingness recycled too. should phone call viewholder.downloadbutton.setonclicklistener
outside of if/else
status sets new listener each time view recycled.
android android-listview android-viewholder
No comments:
Post a Comment