Friday 15 January 2010

listview - How to add button inside listadapter view in android -



listview - How to add button inside listadapter view in android -

here code:

@override public view getview(int position, view convertview, viewgroup parent) { if (inflater == null) inflater = (layoutinflater) activity .getsystemservice(context.layout_inflater_service); if (convertview == null) convertview = inflater.inflate(r.layout.detailedlist_row, null); convertview.setclickable(true); if (imageloader == null) imageloader = appcontroller.getinstance().getimageloader(); networkimageview thumbnail = (networkimageview) convertview .findviewbyid(r.id.thumbnail); textview title = (textview) convertview.findviewbyid(r.id.title); textview cost = (textview) convertview.findviewbyid(r.id.price); textview view = (textview) convertview.findviewbyid(r.id.viewlistin); textview edit = (textview) convertview.findviewbyid(r.id.editlisting); view.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { string userid; // toast.maketext(activity, "view clicked: ", toast.length_short).show(); intent intent = new intent(activity, review.class); activity.startactivity(intent); } }); final film m = movieitems.get(position);

i set onclick textview within adapter,when click textview app forcefulness closed can u guide me wrong code

did create listview? can't tell looking @ code posted. if so, after creating it, can create array adapter , set adapter.

here example:

listview list = (listview) findviewbyid(r.id.listview); // create adapter passing arraylist 3rd parameter arrayadapter<string> arrayadapter = new arrayadapter<string>(first.this, r.layout.button, yourlist); // set adapter list.setadapter(arrayadapter); // register onclicklistener handle click events on each item list.setonitemclicklistener(new adapterview.onitemclicklistener() { // argument position gives index of item clicked public void onitemclick(adapterview<?> arg0, view v, int position, long arg3) { string itemselected = yourlist.get(position); int quantity= yourlist.size(); (int l=0;l<quantity;l++){ if(yourlist.get(l)==itemselected){ intent intent = new intent(first.this, second.class); // rest of code here startactivity(intent); } } } });

since want create button each item of list, can follow tutorial on how button. set r.layout.button name of layout (xml) created button.

android listview button adapter

No comments:

Post a Comment