How to populate listview from two sqlite table rows in listview in Android? -


i have retrieve json string , update,insert , retrieve record 1 one 2 different sqlite table.but how show retrieved data 2 different table in list view concatenating , add 1 one in list-view.can suggest me how this?

here code

 private class getallactivity extends asynctask<void, void, void> {              @override             protected void onpreexecute() {                 super.onpreexecute();                 // showing progress dialog                  pdialog = new progressdialog(allposts_page.this);                 pdialog.setprogressstyle(progressdialog.style_spinner);                 pdialog.setmessage("please wait...");                 pdialog.setindeterminate(false);                 pdialog.setcancelable(false);                 pdialog.show();             }              @override             protected void doinbackground(void... arg0)             {                 getallactivitylist();                 return null;             }              @override             protected void onpostexecute(void result) {                 super.onpostexecute(result);                 // dismiss progress dialog                 if (pdialog.isshowing())                     pdialog.dismiss();             }         }          @override         public void ondestroy(){             super.ondestroy();             if ( pdialog!=null && pdialog.isshowing() )             {                 pdialog.cancel();                  listview listview = (listview)findviewbyid(r.id.listview_allpost);                 mylistadapter adapter = new                        mylistadapter(this,r.layout.all_post_row,str);                 listview.setadapter(adapter);             }         }        public void getallactivitylist()         {             string strurl_getall_activity = "http://xxxx/xxx/xxx.svc/xxx/sync_time/null/xxx/xxxx-xxxx";             log.e("strurl_getall_activity ", " = " + strurl_getall_activity);              inputstream inputstream = null;              try {                 httpclient httpclient = new defaulthttpclient();                 httpresponse httpresponse = httpclient.execute(new httpget(strurl_getall_activity));                 inputstream = httpresponse.getentity().getcontent();                  if(inputstream != null)                     strresult = convertinputstreamtostring(inputstream);                 else                     strresult = "did not work!";                  string jsonstr = strresult;                 log.e("get_vessels_by_type  "," = " + jsonstr);                  if(jsonstr != null)                 {                      try                     {                         jsonobject jsonobj = new jsonobject(jsonstr);                         string jsonresult = jsonobj.tostring().trim();                         log.e("jsonresult ", " = " + jsonresult);                          jsonobject getallactivity_list = jsonobj.getjsonobject("get_all_activitylistresult");                         log.e("getallactivity_list ", " = " + getallactivity_list.tostring());                          string strsync = getallactivity_list.getstring("sync_time");                         log.e("strsync ", " = " + strsync.tostring());                          jsonarray jarr = getallactivity_list.getjsonarray("activitylist");                         log.e("jarr ", " = " + jarr.tostring());                          (int j = 0; j < jarr.length(); j++)                         {                             jsonobject jobjvessels = jarr.getjsonobject(j);                              stractivityid = jobjvessels.getstring("activityid");                             strremark = jobjvessels.getstring("remark");                             strname = jobjvessels.getstring("name");                             strstatus = jobjvessels.getstring("status");                             strtype = jobjvessels.getstring("type");                             struserid = jobjvessels.getstring("userid");                             strobjectid = jobjvessels.getstring("objectid");                             stractiondate = jobjvessels.getstring("actiondate");                             strstarflag= jobjvessels.getstring("starflag");                                 if(dbhelper.isallpostid_exist(stractivityid))                             {                                 //upadte                                 log.e("*******************", "*******************");                                 dbhelper.update_allpost(stractivityid, strremark, strname, strstatus, strtype, struserid, strobjectid, stractiondate, strstarflag);                                 log.e("data updated in ", "company table !!");                                 log.e("*******************", "*******************");                             }                             else                             {                                  log.e("*******************", "*******************");                                 dbhelper.insert_allpost(stractivityid, strremark, strname, strstatus, strtype, struserid, strobjectid, stractiondate, strstarflag);                                 log.e("dats save in ", "allpost succesively !!!!");                                 log.e("*******************", "*******************");                              }                              log.e("*******after else******", "*******************");                             getinspectorname(struserid);                              log.e("*******************", "*******************");                             getvesselname(strobjectid);                         }                      }                     catch(jsonexception je)                     {                     je.printstacktrace();}                 }              }             catch (exception e)             {                 e.printstacktrace();             }         } 

here fetch specific row

public string getinspectorname(string strinspectorid)         {             cursor cursor = null;              sqlitedatabase mdb = dbhelper.getwritabledatabase();             try{                  cursor = mdb.rawquery("select inspector_name inspector inspector_id=?", new string[] {strinspectorid + ""});                  if(cursor.getcount() > 0) {                      cursor.movetofirst();                     inspectorname = cursor.getstring(cursor.getcolumnindex("inspector_name"));                      log.e(" inspectorname "," = " + inspectorname);                 }                  return inspectorname;             }finally {                  cursor.close();             }          }           public string getvesselname(string strvesselidid)         {             cursor cursor = null;              sqlitedatabase mdb = dbhelper.getwritabledatabase();             try{                  cursor = mdb.rawquery("select vessel_name vessellist vessel_id=?", new string[] {strvesselidid + ""});                  if(cursor.getcount() > 0) {                      cursor.movetofirst();                     invesselname = cursor.getstring(cursor.getcolumnindex("vessel_name"));                     log.e(" invesselname "," = " + invesselname);                 }                  return invesselname;             }finally {                  cursor.close();             }          } 

you can use join fetching data 2 tables

note : applying join must have common id both tables.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -