Sunday, 15 August 2010

Android Listview with buttons/checklist -



Android Listview with buttons/checklist -

i'm new listviews on android.

i need layout 4x5 (buttons, checklist , textbox), , thinking of using listviews layout of 1 line of each (4 buttons 4 checklists , 4 textbox), create 5 items.

if 1 line (without listview) i've managed create work.

but when mess listviews not know how utilize "onclick" on buttons , checklist, know line button pressed...

can point me illustration or code this?

thanks

the position managed automatically. if activity extends listactivity or listfragment, need override onlistitemclick.

@override protected void onlistitemclick(listview l, view v, int pos, long id) { super.onlistitemclick(l, v, pos, id); // action }

likewise, if activity not extend listactivity or listfragment, have set listener on listview:

listview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // todo auto-generated method stub } });

of course of study event related whole item in list. instead if want set listener each of view within list item, should within adapter. supposing utilize arrayadapter:

public class customadapter extends arrayadapter<myobject> { private final context context; private arraylist<myobject> list; public customadapter(context context, arraylist<myobject> list) { super(context, r.layout.adapter_row_path, list); this.context = context; this.list = list; } @override public view getview(int position, view convertview, viewgroup parent) { view rowview = convertview; pathholder holder; if(rowview ==null){ layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); rowview = inflater.inflate(r.layout.adapter_row_path, parent, false); holder = new viewholder(); holder.b1 = (button) rowview.findviewbyid(r.id.b1); holder.b2 = (button) rowview.findviewbyid(r.id.b2); rowview.settag(holder); }else { holder = (viewholder) rowview.gettag(); } setrow(holder, position); homecoming rowview; } private void setrow(holder holder, position){ holder.b1.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // action on button 1 (you know position here) } }); holder.b2.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // action on button 2 (you know position here) } }); } } static class viewholder { button b1; button b2; }

android listview button

No comments:

Post a Comment