android - my listview not refresh how to show new values every time -
im insert arraylist on listview inside function cal function on background problem if click multiple times on button listview show duplicate values how refresh or restrict listview show current values every button click remove previous??? button e01;
static arraylist<long> category_id = new arraylist<long>(); static arraylist<string> school_name = new arraylist<string>(); static arraylist<string> menu_name = new arraylist<string>(); static arraylist<string> dish_name = new arraylist<string>(); static arraylist<string> day = new arraylist<string>(); static arraylist<long> vacation_id = new arraylist<long>(); static arraylist<string> vacation_name = new arraylist<string>(); static arraylist<string> vacation_date = new arraylist<string>(); string mydate; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.category_list2); } void cleardata() { category_id.clear(); school_name.clear(); menu_name.clear(); dish_name.clear(); day.clear(); vacation_id.clear(); vacation_name.clear(); vacation_date.clear(); } public class getdatatask extends asynctask<void, void, void> { getdatatask() { if (!prgloading.isshown()) { prgloading.setvisibility(0); txtalert.setvisibility(8); } } @override protected void onpreexecute() { // todo auto-generated method stub } @override protected void doinbackground(void... arg0) { // todo auto-generated method stub parsejsondata(); return null; } @override protected void onpostexecute(void result) { // todo auto-generated method stub prgloading.setvisibility(8); if ((category_id.size() > 0) || ioconnect == 0) { listcategory.setadapter(cla); } } } public void parsejsondata() { cleardata(); selectmenuapi = utils.schoolmenu + cat_name + "&lid=" + schoollevelid; zero1check = valll.tostring(); url = selectmenuapi; url2 = url.replace(" ", "%20"); selectmenuapi2 = utils.schoolvacation; cleardata(); url3 = selectmenuapi2; url4 = url3.replace(" ", "%20"); if (zero1check.equals("0")) byweekdate = todayday + 1; else if (zero1check.equals("1")) { byweekdate = todayday + 2; } try { log.i("url",""+url2); httpclient client = new defaulthttpclient(); httpconnectionparams .setconnectiontimeout(client.getparams(), 15000); httpconnectionparams.setsotimeout(client.getparams(), 15000); httpurirequest request = new httpget(url2); httpresponse response = client.execute(request); httpentity resentity = response.getentity(); _response=entityutils.tostring(resentity); string str2 = ""; str2= _response2; jsonarray school = json2.getjsonarray("data"); (int = 0; < school.length(); i++) { jsonobject object = school.getjsonobject(i); if (count == 1) { count = 0; break; } else if (object.getstring("schedule").equals("weekly")) { if (object.getstring("day").equals(todayday)) { category_id.add((long) i); school_name.add(object.getstring("school_name")); dish_name.add(object.getstring("dish_name")); menu_name.add(object.getstring("menu_title")); day.add(object.getstring("day")); count = count + 1; string[] mval = new string[school.length()]; (int k = 0; k < school.length(); k++) { mval[k] = school.getjsonobject(k).getstring("menu_title"); message = "weekly"; mval2 = mval[0]; } @override public void onclick(view v) { // todo auto-generated method stub switch (v.getid()) { case r.id.e01: new getdatatask().execute(); break; public class thirdstepadapter extends baseadapter { private activity activity; string[] main_menu; public thirdstepadapter(activity act) { this.activity = act; } @override public int getcount() { // todo auto-generated method stub // return main_menu.length; return thirdstep.category_id.size(); } @override public object getitem(int position) { // todo auto-generated method stub return position; } public long getitemid(int position) { // todo auto-generated method stub return position; } public view getview(int position, view convertview, viewgroup parent) { // todo auto-generated method stub viewholder holder; if(convertview == null){ layoutinflater inflater = (layoutinflater) activity .getsystemservice(context.layout_inflater_service); convertview = inflater.inflate(r.layout.main_menu_item, null); holder = new viewholder(); convertview.settag(holder); }else{ holder = (viewholder) convertview.gettag(); } holder.txttext = (textview) convertview.findviewbyid(r.id.txttext); holder.txttext.settext(thirdstep.dish_name.get(position)); return convertview; } static class viewholder { textview txttext; } }
use
notifydatasetchanged();
for example
arraylist<string> data=new arraylist<string>(); mycustum_adaptor adapter = new mycustum_adaptor (data); yourlistview.setadapter(adapter);
set adaptor on first time. , example if add new data array list data this.
data.add("newdata");
so adapter need know change has occur use notifydatasetchanged(); below
adapter.notifydatasetchanged();
this refresh list view new data added.notify data set change after u add or remove data adaptor. hope you
Comments
Post a Comment