this question has answer here:
i using listview baseadapter . every row listview have 2 button. set event on thats buttons.
this problem before link , code now
public class customadapter extends baseadapter{ arraylist<hashmap<string, string>> oslist; context context; private activity parentactivity; private button btndelete; private button btnedit; alertdialog.builder alertdialogbuilder; public string url = "http://192.168.1.103:8080/exdar/api/registeritem/deleting"; public customadapter(arraylist<hashmap<string, string>> oslist,context context, activity parentactivity) { system.out.println("skdjfhksdfjskfjhsdkjfh"); this.context = context; this.oslist = oslist; this.parentactivity = parentactivity; } @override public int getcount() { // todo auto-generated method stub return oslist.size(); } @override public object getitem(int position) { // todo auto-generated method stub return oslist.get(position); } @override public long getitemid(int position) { // todo auto-generated method stub return position; } @override public view getview(final int position, view convertview, viewgroup parent) { layoutinflater lif = (layoutinflater) context.getsystemservice(context.layout_inflater_service); convertview = lif.inflate(r.layout.listitem, null); final textview id = (textview) convertview.findviewbyid(r.id.varid); textview nonota = (textview) convertview.findviewbyid(r.id.varnonota); textview sendername = (textview) convertview.findviewbyid(r.id.varsendername); textview totalamount = (textview) convertview.findviewbyid(r.id.vartotalamount); id.settext(oslist.get(position).get("id")); nonota.settext(oslist.get(position).get("nonota")); sendername.settext(oslist.get(position).get("sendername")); totalamount.settext(oslist.get(position).get("totalamount")); button btnedit = (button) convertview.findviewbyid(r.id.btnedit); button btndelete = (button) convertview.findviewbyid(r.id.btndelete); btnedit.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { toast.maketext(context, "edit ditekan!", toast.length_long).show(); //here perform action want } }); btndelete.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { final dialog dialog = new dialog(parentactivity); dialog.setcontentview(r.layout.yesnodialog); dialog.settitle("delete"); textview text = (textview) dialog.findviewbyid(r.id.rusurewanttodelete); button yes = (button) dialog.findviewbyid(r.id.yes); button no = (button) dialog.findviewbyid(r.id.no); yes.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { string response = ""; system.out.println(id.gettext()); // add code httputils networkget httputils networkget = httputils.getinstance(); arraylist<namevaluepair> parameter = new arraylist<namevaluepair>(); parameter.add(new basicnamevaluepair("id", (string) id.gettext())); try { system.out.println("aaaaaaaaaaaaaaaa"); system.out.println("urlurlurlurl = "+url); response = networkget.posttohttp(url, parameter); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } // until oslist.remove(position); notifydatasetchanged(); dialog.dismiss(); toast.maketext(context, "data deleted.", toast.length_long).show(); } }); no.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub dialog.dismiss(); } }); dialog.show(); } }); return convertview; } }
and error
anyone know why error, , solusion?
yo making http request on main thread, can't in android. use asynctask
or thread
instead. http://developer.android.com/guide/components/processes-and-threads.html
Comments
Post a Comment