android - ListView won't refresh using notifyDataSetChanged -
i'm trying refresh listview adapter class ( non activity class) tried notifydatasetchanged()
wont work , tried call displaylistview()
in adapter class crashes well
this displaylistview()
method in activityclass
cursor cursor = dbhelper.fetchallcountries(); // desired columns bound string[] columns = new string[]{ dbadapter.qty, dbadapter.price, dbadapter.product_name }; // xml defined views data bound int[] = new int[]{ r.id.qtyl, r.id.pricel, r.id.product_namel }; // create adapter using cursor pointing desired data //as layout information dataadapter = new simplecursoradapter( this, r.layout.country_inf, cursor, columns, to, 0); horizontallistview listview = (horizontallistview) findviewbyid(r.id.cartceckoutlist); // assign adapter listview listview.setadapter(dataadapter); dataadapter.notifydatasetchanged();
and adapter class use
package com.abdullahadhaim.finegrillresturant.adater; public class customlistadapter extends baseadapter { context c; // dbhelper mydatabasehelper ; private activity activity; private layoutinflater inflater; private list<movie> movieitems; imageloader imageloader = appcontroller.getinstance().getimageloader(); dbadapter myadapterdb; waiteractivity waiteract; public customlistadapter(activity activity, list<movie> movieitems) { this.activity = activity; this.movieitems = movieitems; } @override public int getcount() { return movieitems.size(); } @override public object getitem(int location) { return movieitems.get(location); } @override public long getitemid(int position) { return position; } @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.list_row, null); if (imageloader == null) imageloader = appcontroller.getinstance().getimageloader(); networkimageview thumbnail = (networkimageview) convertview .findviewbyid(r.id.thumbnail); final textview title = (textview) convertview.findviewbyid(r.id.title); textview price = (textview) convertview.findviewbyid(r.id.rating); // mydatabasehelper=new dbhelper(activity, "cdb", null, 1); myadapterdb = new dbadapter(activity); myadapterdb.open(); waiteract = new waiteractivity(); // getting movie data row final movie m = movieitems.get(position); // thumbnail image thumbnail.setimageurl(m.getthumbnailurl(), imageloader); // title title.settext(m.gettitle()); // price price.settext("price: " + "sr " + string.valueof(m.getprice())); button add = (button) convertview.findviewbyid(r.id.button1); button plus = (button) convertview.findviewbyid(r.id.plus_butt); button minus = (button) convertview.findviewbyid(r.id.minus_butt); final edittext qty = (edittext) convertview .findviewbyid(r.id.edittext1); plus.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub string the_qty = qty.gettext().tostring(); int my_qty = integer.parseint(the_qty) + 1; qty.settext(my_qty + ""); } }); minus.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub string the_qty = qty.gettext().tostring(); int my_qty = integer.parseint(the_qty) - 1; qty.settext(my_qty + ""); } }); add.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { int myqty = integer.parseint(qty.gettext().tostring()); string mytitle = m.gettitle().tostring(); string mycategory = m.getcategory().tostring(); int mycategoryn = m.getordernum(); double myprice = m.getprice() * myqty; if (myqty == 0) toast.maketext(activity, "orders must 1 atleast", toast.length_short).show(); else { myadapterdb.checkifexcist(activity, "productname", mytitle, myqty, myprice, m.getprice(), mytitle, mycategory, mycategoryn + "", myqty); myadapterdb.deletezeroorlessvalues(); } } }); return convertview; } public void notifydatasetchanged() { // todo auto-generated method stub super.notifydatasetchanged(); } }
take @ loaders. think prefered way load data datebase views. loaders callbacks if data has changed , view updated you.
http://developer.android.com/guide/components/loaders.html
here tutorial think: http://code.tutsplus.com/tutorials/android-fundamentals-properly-loading-data--mobile-5673
Comments
Post a Comment