android - loading json data into sqllite db returning blank recycler view -


in previous version of code without sqllite database (that worked), able read in , parse json data remote mysql database contactadapter displayed data in recyclerview within viewpager. each time changed pages, code run asynctask called php script in turn pulled data mysql database different paramaters.

but there lag/delay between changing of pages, decided try , load , store data sqllite database on phone.

i added oppprovider, extends contentprovider , tried tweak asynctask store data mysql database directly sqllite database. unfortunately, did wrong , when run code, no data shown in cardview/recyclerview or view pager. it's blank.

i've checked previous related questions, relate different formulations of reading json sqllite.

i have feeling issue might contentadapter, i've included links other 2 classes below, ideas?
contentadapter.java:

     package com.glam.ui;    import android.content.contenturis; import android.content.contextwrapper; import android.content.intent; import android.content.res.resources; import android.database.cursor; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.graphics.drawable.bitmapdrawable; import android.graphics.drawable.drawable; import android.net.uri; import android.os.bundle; import android.os.environment; import android.support.v7.widget.recyclerview; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.textview; import android.app.activity;  import com.glam.advocatecheckout; import com.glam.applycheckout; import com.glam.checkoutactivity; import com.glam.connectcheckout; import com.glam.givecheckout; import com.glam.learncheckout; import com.glam.oppprovider; import com.glam.productdetail; import com.glam.r; import com.glam.servecheckout; import com.glam.shareproductdetail; import com.glam.utils.contactinfo; import com.squareup.picasso.picasso;  import android.widget.imageview; import android.content.context; import android.widget.toast;   import java.io.bytearrayoutputstream; import java.io.file; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.lang.annotation.target; import java.text.dateformat; import java.text.parseexception; import java.text.simpledateformat; import java.util.date; import java.util.list;  import static android.app.pendingintent.getactivities; import static android.app.pendingintent.getactivity;   public class contactadapter extends recyclerview.adapter<contactadapter.contactviewholder> {  cursor cursor;     int idcolumnindex;     int headingcolumnindex;     int typecolumnindex;     int excerptcolumnindex;     int moreinfocolumnindex;     int opptypecolumnindex;     int startdatecolumnindex;     int enddatecolumnindex;     int contactnamecolumnindex;     int contactemailcolumnindex;     int addresscolumnindex;     int externalurlcolumnindex;      public void swapcursor(cursor c){         cursor = c;         if (cursor!=null) {             cursor.movetofirst();             idcolumnindex = cursor.getcolumnindex(oppprovider.column_oppid);             headingcolumnindex = cursor.getcolumnindex(oppprovider.column_heading);             typecolumnindex = cursor.getcolumnindex(oppprovider.column_type);             excerptcolumnindex = cursor.getcolumnindex(oppprovider.column_excerpt);             moreinfocolumnindex = cursor.getcolumnindex(oppprovider.column_moreinfo);             opptypecolumnindex = cursor.getcolumnindex(oppprovider.column_opptype);             startdatecolumnindex = cursor.getcolumnindex(oppprovider.column_startdate);             enddatecolumnindex = cursor.getcolumnindex(oppprovider.column_enddate);             contactnamecolumnindex = cursor.getcolumnindex(oppprovider.column_contactname);             contactemailcolumnindex = cursor.getcolumnindex(oppprovider.column_contactemail);             addresscolumnindex = cursor.getcolumnindex(oppprovider.column_address);             externalurlcolumnindex = cursor.getcolumnindex(oppprovider.column_externalurl);         }         notifydatasetchanged();         }       public void setextratext(string text){      }     private list<contactinfo> contactlist;      public contactadapter(list<contactinfo> contactlist) {         this.contactlist = contactlist;     }       @override     public int getitemcount() {          //return contactlist.size();         return cursor!=null ? cursor.getcount() : 0;     }      @override     public void onbindviewholder(contactviewholder contactviewholder, int i) {         contactinfo ci = contactlist.get(i);          context context = contactviewholder.vheading.getcontext();         long id = getitemid(i);         cursor.movetoposition(i);         contactviewholder.vheading.settext(cursor.getstring(headingcolumnindex));          if(cursor.getstring(excerptcolumnindex).length()>140)         {             contactviewholder.vstarterexcerpt.settext(cursor.getstring(excerptcolumnindex).substring(0,139) + " . . . ");         }         else         {             contactviewholder.vstarterexcerpt.settext(cursor.getstring(excerptcolumnindex));         }          contactviewholder.vexcerpt.settext(cursor.getstring(excerptcolumnindex));         contactviewholder.vopptype.settext(cursor.getstring(opptypecolumnindex));         contactviewholder.vmoreinfo.settext(cursor.getstring(moreinfocolumnindex));         contactviewholder.vstartdate.settext((cursor.getstring(startdatecolumnindex)));         contactviewholder.venddate.settext((cursor.getstring(enddatecolumnindex)));         contactviewholder.vcontactname.settext(cursor.getstring(contactnamecolumnindex));         contactviewholder.vcontactemail.settext(cursor.getstring(contactemailcolumnindex));         contactviewholder.vaddress.settext(cursor.getstring(addresscolumnindex));         contactviewholder.vexternalurl.settext(cursor.getstring(externalurlcolumnindex));         /*contactviewholder.vheading.settext(ci.heading);         contactviewholder.vtype.settext(ci.type);          if(ci.excerpt.length()>140)         {             contactviewholder.vstarterexcerpt.settext(ci.excerpt.substring(0,139) + " . . .");         }         else         {             contactviewholder.vstarterexcerpt.settext(ci.excerpt);         }          contactviewholder.vexcerpt.settext(ci.excerpt);         contactviewholder.vopptype.settext(ci.opptype);         contactviewholder.vmoreinfo.settext(ci.moreinfo);         contactviewholder.vstartdate.settext((ci.start_date));         contactviewholder.venddate.settext((ci.end_date));         contactviewholder.vcontactname.settext(ci.contact_name);         contactviewholder.vcontactemail.settext(ci.contact_email);         contactviewholder.vaddress.settext(ci.address);         contactviewholder.vexternalurl.settext(ci.external_url);         //contactviewholder.vimage.setimagebitmap(ci.img); */          //contactviewholder.vimage.setimagedrawable(ci.img);     }      @override     public long getitemid(int position) {         cursor.movetoposition(position);         return cursor.getlong(idcolumnindex);     }      @override     public contactviewholder oncreateviewholder(viewgroup viewgroup, int i) {         view itemview = layoutinflater.                 from(viewgroup.getcontext()).                 inflate(r.layout.share_card_view, viewgroup, false);         itemview.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v)             {                 //context whatthef = v.getcontext();                 context whatthef = v.getcontext();                 bundle b = new bundle();                 string key = "keystring";                 string theimage = null;                   textview whazzup = (textview) v.findviewbyid(r.id.txtheading);                 string theheading = whazzup.gettext().tostring();                  textview whatmoreinfo = (textview) v.findviewbyid(r.id.txtmoreinfo);                 string themoreinfo = whatmoreinfo.gettext().tostring();                  textview whatexcerpt = (textview) v.findviewbyid(r.id.txtexcerpt);                 string theexcerpt = whatexcerpt.gettext().tostring();                  textview whattype = (textview) v.findviewbyid(r.id.txttype);                 string thetype = whattype.gettext().tostring();                  textview opptypeview = (textview) v.findviewbyid(r.id.opptype);                 string theopptype = opptypeview.gettext().tostring();                   textview  whatstartdate = (textview)  v.findviewbyid(r.id.txtstartdate);                 string thestartdate = (string) whatstartdate.gettext().tostring();                   textview whatenddate = (textview)  v.findviewbyid(r.id.txtenddate);                 string theenddate = (string)whatstartdate.gettext().tostring();                   textview whatcontactname = (textview)  v.findviewbyid(r.id.txtcontactname);                 string thecontactname = (string)whatcontactname.gettext().tostring();                  textview whatcontactemail = (textview)  v.findviewbyid(r.id.txtcontactemail);                 string thecontactemail = (string)whatcontactemail.gettext().tostring();                  textview whataddress = (textview)  v.findviewbyid(r.id.txtaddress);                 string theaddress = (string)whataddress.gettext().tostring();                  textview whatexternalurl = (textview)  v.findviewbyid(r.id.txtexternalurl);                 string theexternalurl = (string) whatexternalurl.gettext().tostring();                  /*imageview whatimage = (imageview) v.findviewbyid(r.id.oppimg);                 if (whatimage!=null) {                     bitmap imagebitmap = ((bitmapdrawable) whatimage.getdrawable()).getbitmap();                       theimage = imagebitmap.tostring();                 }*/                  theimage = null;                  //toast.maketext(v.getcontext(), "theopptype is: "+theopptype, toast.length_long).show();                 b.putstringarray(key, new string[]{theheading, themoreinfo, thetype,theimage, theexcerpt, getdate(thestartdate), getdate(theenddate), thecontactname, thecontactemail, theaddress,theexternalurl});                 intent bintent;                 switch(theopptype) {                     case "serve":                         bintent = new intent(whatthef, servecheckout.class);                         break;                     case "learn":                         bintent = new intent(whatthef, learncheckout.class);                         break;                     case "give":                         bintent = new intent(whatthef, givecheckout.class);                         break;                     case "apply":                         bintent = new intent(whatthef, applycheckout.class);                         break;                     case "advocate":                         bintent = new intent(whatthef, advocatecheckout.class);                         break;                     case "connect":                         bintent = new intent(whatthef, connectcheckout.class);                         break;                    /* case "null":                         bintent = new intent(whatthef, checkoutactivity.class);                         break;*/                     default:                     bintent = new intent(whatthef, checkoutactivity.class);                         break;                   }                 bintent.putextras(b);                 whatthef.startactivity(bintent);              }         });          return new contactviewholder(itemview);     }      public static class contactviewholder extends recyclerview.viewholder {          //protected imageview vimage;         protected textview vheading;         protected textview vtype;         protected textview vstarterexcerpt;         protected textview vexcerpt;         protected textview vmoreinfo;         protected textview vopptype;         protected textview vstartdate;         protected textview venddate;         protected textview vcontactname;         protected textview vcontactemail;         protected textview vaddress;         protected textview vexternalurl;           public contactviewholder(view v) {             super(v);             //vimage = (imageview) v.findviewbyid(r.id.oppimg);             vheading =  (textview) v.findviewbyid(r.id.txtheading);             vtype = (textview)  v.findviewbyid(r.id.txttype);             vexcerpt = (textview)  v.findviewbyid(r.id.txtexcerpt);             vstarterexcerpt = (textview) v.findviewbyid(r.id.txtstartexcerpt);             vmoreinfo = (textview)  v.findviewbyid(r.id.txtmoreinfo);             vopptype = (textview)  v.findviewbyid(r.id.opptype);             vstartdate = (textview)  v.findviewbyid(r.id.txtstartdate);             venddate = (textview)  v.findviewbyid(r.id.txtenddate);             vcontactname = (textview)  v.findviewbyid(r.id.txtcontactname);             vcontactemail = (textview)  v.findviewbyid(r.id.txtcontactemail);             vaddress = (textview)  v.findviewbyid(r.id.txtaddress);             vexternalurl = (textview)  v.findviewbyid(r.id.txtexternalurl);          }     }       public string getdate (string inputdate) {          dateformat srcdf = new simpledateformat("yyyymmdd");         date date = null;         try {             date = srcdf.parse(inputdate);             dateformat destdf = new simpledateformat("mmm dd, yyyy");              return destdf.format(date);         } catch (parseexception e) {             e.printstacktrace();             return inputdate;         }          }      private void deleteopp (context context, long id) {         context.getcontentresolver()                 .delete (                         contenturis.withappendedid(                                 oppprovider.content_uri,id),null, null);       }  } 

my other code here:

mainfragment -- http://codepad.co/s/d2108a
oppprovider -- http://codepad.co/s/f0e298


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -