How to update listview when loading next new items android? -
hi have popup button. when click pop button, displays radio button.for every radio button selection, fetching datas , updating in ui. problem first radio button updating ui. second radio button , on, ui not updating. how solve this?
code follows:
public class datalist extends activity { private button popupclick; private dialog sortfilterdialog; private radiogroup radiogroup; private radiobutton asctodesradiobutton, destoascradiobutton, hightolowradiobutton, lowtohighradiobutton, popularityradiobutton; private int popupselectionitem; private imageview closebutton; private string sessionid; private string sortname,sortorder; arraylist<sortfilterproducts> personslist; private listview list; private datalistadapter gridadapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); this.requestwindowfeature(window.feature_no_title); setcontentview(r.layout.sortfilterclick); personslist= new arraylist<sortfilterproducts>(); popupclick = (button) findviewbyid(r.id.popupbutton); list=(listview)findviewbyid(r.id.sortfilterlist); gridadapter = new datalistadapter(this, r.layout.sort_filter_listrow, personslist); list.setadapter(gridadapter); popupclick.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { sortfilterdialog = new dialog(sortfilterpopupactivity.this); sortfilterdialog.requestwindowfeature(window.feature_no_title); sortfilterdialog.setcontentview(r.layout.sortfilterrow); radiogroup = (radiogroup) sortfilterdialog .findviewbyid(r.id.radiogroup); asctodesradiobutton = (radiobutton) sortfilterdialog .findviewbyid(r.id.asc_to_des); destoascradiobutton = (radiobutton) sortfilterdialog .findviewbyid(r.id.des_to_asc); hightolowradiobutton = (radiobutton) sortfilterdialog .findviewbyid(r.id.high_to_low); lowtohighradiobutton = (radiobutton) sortfilterdialog .findviewbyid(r.id.low_to_high); popularityradiobutton = (radiobutton) sortfilterdialog .findviewbyid(r.id.popularity); asctodesradiobutton .setonclicklistener(radiobuttononclicklistener); destoascradiobutton .setonclicklistener(radiobuttononclicklistener); hightolowradiobutton .setonclicklistener(radiobuttononclicklistener); lowtohighradiobutton .setonclicklistener(radiobuttononclicklistener); popularityradiobutton .setonclicklistener(radiobuttononclicklistener); } private final onclicklistener radiobuttononclicklistener = new onclicklistener() { @override public void onclick(view v) { switch (popupselectionitem = v.getid()) { case r.id.asc_to_des: sortname="atoz"; sortorder="sort_asc"; new sortfilterelement().execute(); //new asctodeselements().execute(); break; case r.id.des_to_asc: sortname="atoz"; sortorder="sort_desc"; new sortfilterelement().execute(); //new desctoascelements().execute(); break; case r.id.high_to_low: sortname="lowtohigh"; sortorder="sort_asc"; new sortfilterelement().execute(); //new pricehightolow().execute(); break; case r.id.low_to_high: sortname="lowtohigh"; sortorder="sort_desc"; //new pricelowtohigh().execute(); new sortfilterelement().execute(); break; case r.id.popularity: sortname="popularity"; sortorder="sort_asc"; //new popularity().execute(); new sortfilterelement().execute(); break; default: } sortfilterdialog.dismiss(); } class sortfilterelement extends asynctask<string,string,string>{ progressdialog dialog; @override protected void onpreexecute() { // todo auto-generated method stub super.onpreexecute(); dialog=new progressdialog(sortfilterpopupactivity.this); dialog.setmessage("loading, please wait"); dialog.settitle("connecting server"); dialog.show(); dialog.setcancelable(false); } @override protected string doinbackground(string... args) { try { soapserializationenvelope env = new soapserializationenvelope( soapserializationenvelope.ver11); env.dotnet = false; env.xsd = soapserializationenvelope.xsd; env.enc = soapserializationenvelope.enc; if (sessionid == null) { jsonobject json = new jsonobject(); json.put("page", "1"); json.put("limit", "10"); json.put("sort_name", sortname); json.put("sort_order", sortorder); string params = json.tostring(); requests.addproperty("args", params); env.setoutputsoapobject(requests); androidhttptransport.call("", env); object results = env.getresponse(); log.e("sort results", results.tostring()); if (results.tostring() != null) { jsonobject jsono = new jsonobject(results .tostring()); jsonarray jarray = jsono .getjsonarray("result"); (int = 0; < jarray.length(); i++) { jsonobject object = jarray.getjsonobject(i); sortfilterproducts products = new sortfilterproducts(); string id = object.getstring("id"); int productprice = object.getint("price"); string imageurl = object .getstring("image_url"); int ratings=object.getint("ratings"); products.setproductname(productname); products.setimageurl(imageurl); personslist.add(products); } } } catch (exception e) { e.printstacktrace(); } return null; } @override protected void onpostexecute(string result) { // todo auto-generated method stub super.onpostexecute(result); dialog.cancel(); gridadapter.notifydatasetchanged(); } } }; }); } }
and datalistadapter:
public class datalistadapter extends baseadapter { layoutinflater layoutinflater; int resource; viewholder viewholder; activity activity; public imageloader loader; private final arraylist<sortfilterproducts> itemlists; public datalistadapter(activity a, int resource, arraylist<sortfilterproducts> itemlist) { layoutinflater = (layoutinflater) .getsystemservice(context.layout_inflater_service); resource = resource; itemlists = itemlist; activity = a; loader = new imageloader(a.getapplicationcontext()); } @override public int getcount() { return itemlists.size(); } @override public object getitem(int position) { return itemlists.get(position); } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { view v= convertview; try { if(v==null){ viewholder = new viewholder(); v = layoutinflater.inflate(resource, null); viewholder.productname=(textview)v.findviewbyid(r.id.productname); viewholder.productprice=(textview)v.findviewbyid(r.id.price); v.settag(viewholder); } else{ viewholder = (viewholder) v.gettag(); } final string productname=itemlists.get(position).getproductname(); final int productprice=itemlists.get(position).getproductprice(); viewholder.productname.settext(productname); viewholder.productprice.settext(integer.tostring(productprice)); } catch (exception ex) { ex.printstacktrace(); } return v; } static class viewholder { public textview productname,productprice; } }
invalidate items of listview while expanding arraylist<sortfilterproducts> passed adapter.
list.invalidateviews();
good luck. :)
Comments
Post a Comment