android - ListView Checkbox repeated every 4th items -
i have listview filled checkboxes. when click on checkbox, 4th checkbox , multiplications (8th, 12th, etc..) checked automatically without me clicking on them.
updated code
public class caractivity extends activity implements downloadresultreceiver.receiver { private downloadresultreceiver mreceiver; list<item> items; string carnumber; /** * attention: auto-generated implement app indexing api. * see https://g.co/appindexing/androidstudio more information. */ private googleapiclient client; @override protected void oncreate(bundle savedinstancestate) { button submit; super.oncreate(savedinstancestate); setcontentview(r.layout.activity_car); bundle b = this.getintent().getextras(); string url = b.getstring("url"); carnumber = b.getstring("carnumber"); string model = b.getstring("model"); final string category = b.getstring("category"); submit = (button) findviewbyid(r.id.submit); submit.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { string url = null; if (category.equals("الأجهزة الطبية")) { url = "http://192.168.1.136/final/medical_equipments/insert.php"; } else if (category.equals("الأفراد")) { url = "http://192.168.1.136/final/persons/insert.php"; } else if (category.equals("التدريب")) { url = "http://192.168.1.136/final/training/insert.php"; } else if (category.equals("الصيانة الميكانيكية")) { url = "http://192.168.1.136/final/mechanical_repair/insert.php"; } else if (category.equals("الصيانة الطبية")) { url = "http://192.168.1.136/final/medical_repair/insert.php"; } else if (category.equals("المستلزمات الطبية")) { url = "http://192.168.1.136/final/medical_requirments/insert.php"; } else if (category.equals("تجهيزات كابينة السائق")) { url = "http://192.168.1.136/final/driver_equipment/insert.php"; } else if (category.equals("سجلات السيارة")) { url = "http://192.168.1.136/final/car_records/insert.php"; } new submititems().execute(url); } }); //getactionbar().settitle(""); //if (connection.isconnectedtointernet(getapplicationcontext())) { if (true) { /* starting download service */ mreceiver = new downloadresultreceiver(new handler()); mreceiver.setreceiver(this); intent intent = new intent(intent.action_sync, null, this, downloadservice.class); /* send optional extras download intentservice */ intent.putextra("url", url); string data = null; try { data = urlencoder.encode("model", "utf-8") + "=" + urlencoder.encode(model, "utf-8"); } catch (unsupportedencodingexception e) { e.printstacktrace(); } intent.putextra("data", data); intent.putextra("receiver", mreceiver); intent.putextra("requestid", 101); startservice(intent); } else { new alertdialog.builder(caractivity.this) .settitle("oops") .setmessage("no internet connection!") .setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { } }).show(); } // attention: auto-generated implement app indexing api. // see https://g.co/appindexing/androidstudio more information. client = new googleapiclient.builder(this).addapi(appindex.api).build(); } @override public void onstart() { super.onstart(); // attention: auto-generated implement app indexing api. // see https://g.co/appindexing/androidstudio more information. client.connect(); action viewaction = action.newaction( action.type_view, // todo: choose action type. "car page", // todo: define title content shown. // todo: if have web page content matches app activity's content, // make sure auto-generated web page url correct. // otherwise, set url null. uri.parse("http://host/path"), // todo: make sure auto-generated app deep link uri correct. uri.parse("android-app://com.example.khloud.qery/http/host/path") ); appindex.appindexapi.start(client, viewaction); } @override public void onstop() { super.onstop(); // attention: auto-generated implement app indexing api. // see https://g.co/appindexing/androidstudio more information. action viewaction = action.newaction( action.type_view, // todo: choose action type. "car page", // todo: define title content shown. // todo: if have web page content matches app activity's content, // make sure auto-generated web page url correct. // otherwise, set url null. uri.parse("http://host/path"), // todo: make sure auto-generated app deep link uri correct. uri.parse("android-app://com.example.khloud.qery/http/host/path") ); appindex.appindexapi.end(client, viewaction); client.disconnect(); } class submititems extends asynctask<string, string, string> { private progressdialog pdialog; @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(caractivity.this); pdialog.setmessage("attempting submitting..."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); } @override protected string doinbackground(string... args) { string url = args[0]; try { (item item : items) { string data = urlencoder.encode("carnumber", "utf-8") + "=" + urlencoder.encode(carnumber, "utf-8") + "&" + urlencoder.encode("itemname", "utf-8") + "=" + urlencoder.encode(item.getname(), "utf-8") + "&" + urlencoder.encode("found", "utf-8") + "=" + urlencoder.encode(item.getfound() + "", "utf-8") + "&" + urlencoder.encode("notfound", "utf-8") + "=" + urlencoder.encode(item.getnotfound() + "", "utf-8") + "&" + urlencoder.encode("working", "utf-8") + "=" + urlencoder.encode(item.getworking() + "", "utf-8") + "&" + urlencoder.encode("notworking", "utf-8") + "=" + urlencoder.encode(item.getnotworking() + "", "utf-8") + "&" + urlencoder.encode("notes", "utf-8") + "=" + urlencoder.encode(item.getnotes(), "utf-8"); connection.getjsonfromurl(url, data); } } catch (unsupportedencodingexception e) { e.printstacktrace(); } catch (exception e) { return null; } return "save successfully"; } protected void onpostexecute(string file_url) { pdialog.dismiss(); if (file_url != null) { toast.maketext(caractivity.this, file_url, toast.length_short) .show(); finish(); } } } @override public void onreceiveresult(int resultcode, bundle resultdata) { switch (resultcode) { case downloadservice.status_running: break; case downloadservice.status_finished: string response = resultdata.getstring("result"); if (response == null) log.d("respooo", "null"); intializeprocess(response); break; case downloadservice.status_error: /* handle error */ string error = resultdata.getstring("error"); log.d("error", error); break; } } private void intializeprocess(string response) { log.d("response", response); itemsretrieval itemretrieval = new itemsretrieval(); if (itemretrieval.getmainapi(response)) { // load.setvisibility(view.gone); items = itemretrieval.getitems(); log.e("items size", items.size() + ""); dowork(); //getactionbar().settitle(singer.getname()); //getactionbar().seticon(r.drawable.singer_icon); } } private void dowork() { populatelistview(); registerclickcallback(); } private void populatelistview() { arrayadapter<item> adapter = new mylistadapter(); listview list = (listview) findviewbyid(r.id.items); list.setadapter(adapter); } private void registerclickcallback() { listview list = (listview) findviewbyid(r.id.items); list.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(final adapterview<?> parent, view viewclicked, final int position, long id) { final item item = items.get(position); /////////////////////////////////// } }); } /////////////////// private class mylistadapter extends arrayadapter<item> { public mylistadapter() { super(caractivity.this, r.layout.item, items); } @override public view getview(int position, view convertview, viewgroup parent) { // make sure have view work (may have been given null) item item = items.get(position); viewholder holder = null; view itemview = convertview; if (itemview == null){ itemview = getlayoutinflater().inflate(r.layout.item, parent, false); holder = new viewholder(); holder.textview1 = (textview) itemview.findviewbyid(r.id.textview1); itemview.settag(holder); } else{ holder = (viewholder) itemview.gettag(); } //set value of item name - here avoid repeating items when convertview null (happens when scroll end of list) holder.textview1.settext(item.getname()); return itemview; } private class viewholder { textview textview1; } }}`
you should implement viewholder
pattern adapter - change
adapter code this: private class mylistadapter extends arrayadapter<item> { public mylistadapter() { super(caractivity.this, r.layout.item, items); } @override public view getview(int position, view convertview, viewgroup parent) { // make sure have view work (may have been given null) item item = items.get(position); viewholder holder = null; view itemview = convertview; if (itemview == null){ itemview = getlayoutinflater().inflate(r.layout.item, parent, false); holder = new viewholder(); holder.textview1 = (textview) itemview.findviewbyid(r.id.textview1); itemview.settag(holder); } else{ holder = (viewholder) itemview.gettag(); } //set value of item name - here avoid repeating items when convertview null (happens when scroll end of list) holder.textview1.settext(item.getname()); return itemview; } private class viewholder { textview textview1; } }
i hope helps. way, think problem similar 1 discussed here, , here.
Comments
Post a Comment