json - Refresh listview after click Android -


i have android app (created tutorials) creates list json , depending on data creates yellow or black background.

what want when person clicks on item list, data transmitted server (works) want refresh list because data has changed (cannot work) can me?

this code:

public class androidjsonparsingactivity extends listactivity { // url make request private static string url = "http://www.somesite.com/kaku/kaku_list.php/";  // json node names private static final string tag_ontvangers = "ontvangers"; private static final string tag_id = "id"; private static final string tag_beschrijving = "beschrijving"; private static final string tag_kanaal = "kanaal"; private static final string tag_nummer = "nummer"; private static final string tag_status = "status";  // contacts jsonarray jsonarray ontvangers = null;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      // hashmap listview     arraylist<hashmap<string, string>> ontvanger = new arraylist<hashmap<string, string>>();      // creating json parser instance     jsonparser jparser = new jsonparser();      // getting json string url     jsonobject json = jparser.getjsonfromurl(url);      try {         // getting array of contacts         ontvangers = json.getjsonarray(tag_ontvangers);          // looping through contacts         for(int = 0; < ontvangers.length(); i++){             jsonobject c = ontvangers.getjsonobject(i);              // storing each json item in variable             string id = c.getstring(tag_id);             string beschrijving = c.getstring(tag_beschrijving);             string kanaal = c.getstring(tag_kanaal);             string nummer = c.getstring(tag_nummer);             string status = c.getstring(tag_status);              // creating new hashmap             hashmap<string, string> map = new hashmap<string, string>();              // adding each child node hashmap key => value             map.put(tag_id, id);             map.put(tag_beschrijving, beschrijving);             map.put(tag_kanaal, kanaal);             map.put(tag_nummer, nummer);             map.put(tag_status, status);               // adding hashlist arraylist             ontvanger.add(map);         }     } catch (jsonexception e) {         e.printstacktrace();     }       /**      * updating parsed json data listview      * */     listadapter adapter = new ontvangeradapter(this, ontvanger,             r.layout.list_item,             new string[] {  tag_beschrijving, tag_id, tag_status }, new int[] {             r.id.beschrijving, r.id.ontvanger_id, r.id.status});       setlistadapter(adapter);     // selecting single listview item     listview lv = getlistview();      // launching new screen on selecting single listitem     lv.setonitemclicklistener(new onitemclicklistener() {          @override         public void onitemclick(adapterview<?> parent, view view,                 int position, long id) {                             // getting values selected listitem             string ontvanger_id = ((textview) view.findviewbyid(r.id.ontvanger_id)).gettext().tostring();             jsonparser jparser = new jsonparser();             string url1 = "http://www.somesite.com/kaku/action.php?id="+ontvanger_id+"/" ;             // getting json string url             jparser.getjsonfromurl(url1);            }        });   }  } 

from comments

listadapter not have notifydatasetchanged()

http://developer.android.com/reference/android/widget/listadapter.html

you use arrayadapter or baseadapter. better use custom listview custom adapter extending either arrayadapter of baseadapter.(you can customize listview items easily).

http://developer.android.com/reference/android/widget/arrayadapter.html

http://developer.android.com/reference/android/widget/baseadapter.html#notifydatasetchanged()

public void notifydatasetchanged ()

added in api level 1

notifies attached observers underlying data has been changed , view reflecting data set should refresh itself.


Comments