Android clear listview linked to SQLite -
i have following activity populating listview sqlite. when click on empty
delete table content correctly , refresh cartactivity appears empty. if add new element in cart old elements appears again in listview , (correctly) not in db. if close application listview update correctly.
tried give @ similar question, tried notify
nothing happens. wrote "you delete data not entries" i'm not able to.
how solve issue?
any appreciated. in advance.
public class cartactivity extends activity { listview list; context context; sessionmanagement session; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_cart); typeface font = typeface.createfromasset(this.getassets(), "font/varelaround-regular.ttf"); context = getapplicationcontext(); session = new sessionmanagement(context); final carthandler db = new carthandler(this); log.d("reading: ", "reading contacts.."); final list<cartrow> products = db.getallproducts(); (cartrow cn : products) { string log = "id: "+cn.getid()+" ,name: " + cn.getname() + " ,number: " + cn.getnumber() + " ,pieces: " + cn.getpieces() + " ,price: " + cn.getprice() + " ,tot: " + cn.gettotprice(); log.d("nome: ", log); } if(products.isempty() ){ //intent intent = new intent(getapplicationcontext(),menuactivity.class); //intent.setflags(intent.flag_activity_clear_top); //intent.setflags(intent.flag_activity_clear_task); //startactivity(intent); toast.maketext(this, "", toast.length_long).show(); //finish(); } else { final carthandler mdb = new carthandler(this); getitemsfromdatabase(mdb); final customcarterlist adapter = new customcarterlist(cartactivity.this); list = (listview) findviewbyid(r.id.cart); list.setadapter(adapter); button empty = (button) findviewbyid(r.id.emptycart); empty.settypeface(font); empty.setonclicklistener(new view.onclicklistener(){ public void onclick(view v){ db.deleteall(); //mdb.deleteall(); intent intent = new intent(cartactivity.this, cartactivity.class); intent.setflags(intent.flag_activity_clear_top); startactivity(intent); finish(); } }); button proceed = (button) findviewbyid(r.id.proceed); proceed.settypeface(font); proceed.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { if (!session.isloggedin()) { intent intent = new intent(cartactivity.this, loginactivity.class); intent.setflags(intent.flag_activity_clear_top); startactivity(intent); finish(); } else { intent intent = new intent( getapplicationcontext(), checkoutactivity.class ); startactivity(intent); } } }); } } public void getitemsfromdatabase(carthandler mdb) { cursor cursor = null; try{ sqlitedatabase db =mdb.getreadabledatabase(); cursor=db.rawquery("select * products", null); while (cursor.movetonext()){ log.e("cart", cursor.getstring(1)+":"+cursor.getstring(2)+":"+cursor.getstring(3)+":"+cursor.getstring(4)+":"+cursor.getstring(5)); cartrow.itemidlist.add(cursor.getstring(0)); cartrow.itemnamelist.add(cursor.getstring(1)); cartrow.itemquantitylist.add(cursor.getstring(2)); if (cursor.getstring(3).equals("0")){ cartrow.itempieceslist.add("pieces: 1");} else{ cartrow.itempieceslist.add("pieces: "+cursor.getstring(3));} cartrow.itempricelist.add(cursor.getstring(4) + ".00€"); cartrow.itemtotpricelist.add(cursor.getstring(5)+".00€"); } cursor.close(); }catch (sqlexception e){ log.e("db error", e.tostring()); e.printstacktrace(); } }
use adapter.notifydatasetchanged()
instead of notify.
Comments
Post a Comment