java - How to change the position of listview items? -


i have app gets data cloud , displays in listview. data getting 2 source 1 api , other 1 parse cloud. data api displayed first , takes position of top listview items , data parse cloud displayed later , takes lower position. want data taken parse cloud take position in top listview items(when data has been retrieved) , data taken api move down.

private class getcontacts extends asynctask<void, void, void> {      @override     protected void onpreexecute() {         super.onpreexecute();         // showing progress dialog         pdialog = new progressdialog(getactivity());         pdialog.setmessage("please wait...");         pdialog.setcancelable(false);         pdialog.show();         list.setadapter(adapter);        }      @override     protected void doinbackground(void... arg0) {         getip = getipaddress();          // creating service handler class instance         servicehandler sh = new servicehandler();         // making request url , getting response         string jsonstr = sh                 .makeservicecall(url + getip, servicehandler.get);          parsequery<parseobject> query = parsequery.getquery("ads");         query.findinbackground(new findcallback<parseobject>() {             public void done(list<parseobject> scorelist, parseexception e) {                     (int = 0; < scorelist.size(); i++) {                          try {                             parsefile file = (parsefile) scorelist.get(i)                                     .get("appimage");                             hashmap<string, string> contact = new hashmap<string, string>();                              string desc = scorelist.get(i)                                     .getstring("desc");                             string apptitle = scorelist.get(i).getstring(                                     "apptitle");                             string appurl = scorelist.get(i).getstring(                                     "appurl");                             string imageurl = file.geturl();                             string existing_user = scorelist.get(i)                                     .getstring("existinguser");                             if (existing_user.equals("true")) {                                 existing = true;                             } else if (existing_user.equals("false")) {                                 existing = false;                             }                             // adding each child node hashmap key =>                             // value                             if (apptitle != null) {                                 contact.put(tag_name, apptitle);                             } else {                                 contact.put(tag_name,                                         "ultimate voice recorder");                             }                             if (desc != null) {                                 contact.put(tag_desc, desc);                             } else {                                 contact.put(tag_desc,                                         "desc");                             }                              if (imageurl != null) {                                 contact.put(tag_photo_url, imageurl);                             } else {                                 contact.put(                                         tag_photo_url,                                         "url");                             }                             if (appurl != null) {                                 contact.put(tag_app_url, appurl);                             } else {                                 contact.put(                                         tag_app_url,                                         "appurl");                             }                              // adding contact contact list                             appslist.add(contact);                             adapter.notifydatasetchanged();                          } catch (exception ex) {                             ex.printstacktrace();                             bugsensehandler.sendexception(ex);                          }                     }                     // toast.maketext(todayspicks.this, scorelist.size(),                     // toast.length_short).show();                     log.d("score", "retrieved " + scorelist.size()                             + " scores");              }         });         if (jsonstr != null) {             try {                 jsonobject jsonobj = new jsonobject(jsonstr);                  // getting json array node                 contacts = jsonobj.getjsonarray(tag_apps);                  // looping through contacts                 (int = 0; < contacts.length(); i++) {                     jsonobject c = contacts.getjsonobject(i);                      string name = c.getstring(tag_name);                     string email = c.getstring(tag_desc);                      // phone node json object                     string photourl = c.getstring(tag_photo_url);                     string appurl = c.getstring(tag_app_url);                     // tmp hashmap single contact                     hashmap<string, string> contact = new hashmap<string, string>();                      // adding each child node hashmap key => value                     contact.put(tag_name, name);                     contact.put(tag_desc, email);                     contact.put(tag_photo_url, photourl);                     contact.put(tag_app_url, appurl);                      // adding contact contact list                     appslist.add(contact);                 }              } catch (jsonexception e) {                 e.printstacktrace();                 bugsensehandler.sendexception(e);             }         } else {             log.e("servicehandler", "couldn't data url");         }          return null;     }      @override     protected void onpostexecute(void result) {         super.onpostexecute(result);         // dismiss progress dialog         try {             if ((pdialog != null) && pdialog.isshowing()) {                 pdialog.dismiss();             }         } catch (final exception e) {             bugsensehandler.sendexception(e);         } {             pdialog = null;         }         adapter.notifydatasetchanged();        }  } 

this how data displayed http://www.image-share.com/ijpg-2687-211.html

you create arraylist of custom-defined objects holds different kinds of information want. in listadapter, return appropriate data. when asynctask returns, update arraylist have new elements come first, call listadapter.notifydatasetchanged.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -