listview - Android CheckBox Delete -


i having serious issues this, have listview populated entries in database, have custom row each of row in listview (textview1|textview2|textview3|checkbox).

all want put listener on each of check boxes when checked removed listview , deleted database. have function deletes row database when passed value textview1.

the issue having trying row id checked box or textview value. have searched everywhere still cant work

checkbox

cursor cursor = db.getallitems();      //string[] columns = new string[] {db.key_name, db.key_code, db.key_rowid};     final string[] columns = new string[] {db.key_item_name, db.key_measurement, db.key_unit};      int[] = new int[] {r.id.ingredientname, r.id.ingredientmeasurement, r.id.ingredientunit};      final simplecursoradapter mycursoradapter = new simplecursoradapter(this,r.layout.row4, cursor, columns, to, 0);      final listview shoppinglist = (listview) findviewbyid(r.id.shoppinglist);     shoppinglist.setclickable(false);     //shoppinglist.setchoicemode(shoppinglist.choice_mode_single);     shoppinglist.setadapter(mycursoradapter);      checkbox check = (checkbox) findviewbyid(r.id.checkbox1);     check.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {         @override         public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {             if (buttonview.ischecked()) {                 //how row_id or text view value?             } else {                 //do nothing             }             }          }); 

as far know not possible implementation. have create custom adapter

public class customadapter extends simplecursoradapter{      public customadapter(context context, int layout, cursor c, string[] from, int[] to) {         super(context, layout, c, from, to);     }      public view getview(final int position, view convertview, viewgroup parent){         view view = super.getview(position, convertview, parent);         checkbox check = (checkbox) findviewbyid(r.id.checkbox1);         check.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {         @override         public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {             if (buttonview.ischecked()) {                 // position give position of clicked element can fetch data             } else {                 //do nothing             }             }          });         return view;     } } 

you can use

customadapter adapter = new customadapter(this, r.layout.row_layout, cursor, from, to); list.setadapter(adapter); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -