java - How to get the id of a button in a listview -
i have customized widget textview , button. list view contains list of customized widget. want know on button there clicked. in facebook each post has react button , when click on go specific page.
use below code create custom list. can create holder class hold button , textview object. helpful detect button click using holder class.
class myadpter extends arrayadapter { int layout; arraylist<data> arr; context con; public myadpter(context context, int textviewresourceid, arraylist<data> objects) { super(context, textviewresourceid, objects); layout=textviewresourceid; arr= objects; con=context; // todo auto-generated constructor stub } @override public view getview(int position, view convertview, viewgroup parent) { // todo auto-generated method stub final viewholder holder=new viewholder(); if(convertview==null) { layoutinflater inflator=(layoutinflater) con.getsystemservice(context.layout_inflater_service); convertview=inflator.inflate(layout, parent, false); holder.tv=(textview) convertview.findviewbyid(r.id.text); holder.btn=(button) convertview.findviewbyid(r.id.button); } holder.btn.settext("data"); holder.btn.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub toast.maketext(con, ""+holder.btn.gettext(), 800).show(); } }); holder.tv.settext("data"); return convertview; } @override public int getcount() { // todo auto-generated method stub return super.getcount(); } } static class viewholder { textview tv; button btn; }
Comments
Post a Comment