Android How to add clickable button in listview? -
i displaying listview movie , right side display button download when scroll listview button event interchange(repaint) every time,i have set button text cancel when user press download button , downloading started when scroll down list button text change initial name download , event interchange.
static class listitemcontainers { //imageview imgicon; //textview txttitle; progressbar pb; textview progressval; button downloadbutton; textview title; imageview imageicon; linearlayout layout; } @override public view getview(int position, view convertview,final viewgroup parent) { // todo auto-generated method stub final listitemcontainers holder; log.d("game name in adapter",":"+gamelistname.get(position)); view vi=convertview; final listitemcontainers holdz; relativelayout rl; if(convertview==null) { convertview = inflater.inflate(r.layout.list_row, null); holder = new listitemcontainers(); holder.title = (textview)convertview.findviewbyid(r.id.game_name); holder.imageicon=(imageview)convertview.findviewbyid(r.id.listicon); rl=(relativelayout)convertview.findviewbyid(r.id.game_row); holder.layout = (linearlayout )convertview.findviewbyid(r.id.dynamic); holder.progressval=(textview)convertview.findviewbyid(r.id.progressval); holder.pb=(progressbar)convertview.findviewbyid(r.id.progressbar1); holder.pb.setvisibility(view.invisible); holder.downloadbutton=(button)convertview.findviewbyid(r.id.button1); convertview.settag(holder); final listitemcontainers hold = holder; //setbuttonclick(hold ); } else { holder = (listitemcontainers)convertview.gettag(); } holder.title.settext(gamelistname.get(position)); holder.imageicon.setimagedrawable(gameicon.get(position)); holder.downloadbutton.settext("dwnload"+position); holder.downloadbutton.setid(position); holder.pb.setid(position+1000); setbutton(holder,convertview,position); return convertview; } int globalid; public void setbutton(final listitemcontainers holder,final view v,final int id){ holder.downloadbutton=(button)v.findviewbyid(id); holder.pb=(progressbar)v.findviewbyid(id+1000); holder.downloadbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { toast.maketext(activity, "click by:"+id, toast.length_short).show(); if(checkflag==true){ checkflag=false; globalid=id; updateprogresbar.listcntr=holder; up=new updateprogresbar(holder.pb,activity,v); up.execute(""); canclebuttonclick(holder,v,id); } else{ toast.maketext(activity, "please wait", toast.length_short).show(); } } }); }
you should use view holder inside listview or have check convertview null before inflating ui.
Comments
Post a Comment