android - RecyclerView is not being populated with items -


i trying send volley request populate recyclerviews reason can fathom, recyclerview not populated. data fetched quite alright, can see logcat.

after loading see blank page, blank , empty page.

these codes:

sample jsoup

{   "found": 4,   "site_id": 1,   "comments": [     {       "id": 26934,       "post": {         "id": 194784,         "type": "post",         "title": "lorem ipsum dummy text",       },       "author": {         "email": false,         "avatar_url": "http://1.gravatar.com/avatar/af61ad05da322fccae2bd02f7062e357?s=96&d=wavatar&r=g",       },       "date": "2016-05-28t02:54:35+01:00",       "content": "<p>it long established fact reader distracted readable content of page when looking @ layout</p>\n",       "status": "approved",      },     {           "id": 26934,           "post": {             "id": 194784,             "type": "post",             "title": "contrary popular belief, lorem ipsum",           },           "author": {             "email": false,             "avatar_url": "http://1.gravatar.com/avatar/af61ad05da322fccae2bd02f7062e357?s=96&d=wavatar&r=g",           },           "date": "2016-05-28t02:54:35+01:00",           "content": "<p>richard mcclintock, latin professor @ hampden-sydney college in virginia</p>\n",           "status": "approved",      },     {           "id": 26934,           "post": {             "id": 194784,             "type": "post",             "title": "lorem ipsum dummy text",           },           "author": {             "email": false,             "avatar_url": "http://1.gravatar.com/avatar/af61ad05da322fccae2bd02f7062e357?s=96&d=wavatar&r=g",           },           "date": "2016-05-28t02:54:35+01:00",           "content": "<p>it long established fact reader distracted readable content of page when looking @ layout</p>\n",           "status": "approved",          },         {               "id": 26934,               "post": {                 "id": 194784,                 "type": "post",                 "title": "lorem ipsum dolor sit amet, consectetur adipiscing elit",               },               "author": {                 "email": false,                 "avatar_url": "http://1.gravatar.com/avatar/af61ad05da322fccae2bd02f7062e357?s=96&d=wavatar&r=g",               },               "date": "2016-05-28t02:54:35+01:00",               "content": "<p>sed ut porttitor nunc. cras scelerisque lobortis diam, nec placerat lacus aliquam eu. ut eros non libero porta commodo. nulla odio lectus, vestibulum ut ultrices eget</p>\n",               "status": "approved",          },   ] } 

commentitem

public class commentitem {     private string comt_name;     private string comt_if_auth;     private string comt_cont;     private string comt_timest;      public string getcomt_imageurl() {         return comt_image_url;     }      public void setcomt_imageurl(string comt_image) {         this.comt_image_url = comt_image;     }      public string getcomt_name() {         return comt_name;     }      public void setcomt_name(string comt_name) {         this.comt_name = comt_name;     }      public string getcomt_if_auth() {         return comt_if_auth;     }      public void setcomt_if_auth(string comt_if_auth) {         this.comt_if_auth = comt_if_auth;     }      public string getcomt_cont() {         return comt_cont;     }      public void setcomt_cont(string comt_cont) {         this.comt_cont = comt_cont;     }      public string getcomt_timest() {         return comt_timest;     }      public void setcomt_timest(string comt_timest) {         this.comt_timest = comt_timest;     } } 

commentfragment

public class commentfragment extends fragment {      private final string tag = "commentfragment";     private progressbar mprogressbar;     private textview comtheader;      //creating list of comments     private list<commentitem> mcommentitems;      //creating views     recyclerview mrecyclerview;     private recyclerview.adapter madapter;     linearlayoutmanager mlayoutmanager;       private string comturl;     public commentfragment() {         // required empty public constructor     }       @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         log.d(tag, "oncreate view called");         comturl = getarguments().getstring("commenturl");         log.d(tag, comturl);         // inflate layout fragment         view view = inflater.inflate(r.layout.fragment_comment, container, false);         mrecyclerview = (recyclerview) view.findviewbyid(r.id.comment_recyclerm);         mprogressbar = (progressbar) view.findviewbyid(r.id.comt_prog);         comtheader = (textview) view.findviewbyid(r.id.comt_head);          mlayoutmanager = new linearlayoutmanager(getactivity());         mrecyclerview.setlayoutmanager(mlayoutmanager);          loadcomment();          mcommentitems = new arraylist<>();         mrecyclerview.setadapter(madapter);         madapter = new commentadapter(mcommentitems, getactivity());          return view;     }      private void loadcomment() {         log.d(tag, "loadcomment called");         mprogressbar.setvisibility(view.visible);          jsonobjectrequest comments = new jsonobjectrequest(comturl, null,                 new response.listener<jsonobject>() {                     @override                     public void onresponse(jsonobject response) {                         log.d(tag, "onresponse loadcomment called");                         parsecomment(response);                         if (mprogressbar != null) {                             mprogressbar.setvisibility(view.gone);                         }                     }                 },                 new response.errorlistener() {                     @override                     public void onerrorresponse(volleyerror error) {                         if (mprogressbar != null) {                             mprogressbar.setvisibility(view.gone);                         }                      }                 });         int sockettimeout = 10000;         retrypolicy policy = new defaultretrypolicy(sockettimeout, defaultretrypolicy.default_max_retries, defaultretrypolicy.default_backoff_mult);         comments.setretrypolicy(policy);          requestqueue requestqueue = volley.newrequestqueue(getactivity());          requestqueue.add(comments);       }      public void parsecomment(jsonobject object) {         log.d(tag,  "parsing comments");         try {             string found = object.getstring("found");             if (found.equals("1")) {                 comtheader.settext(getstring(r.string.comment, found));             } else {                 comtheader.settext(getstring(r.string.comments, found));             }              jsonarray commentarray = object.getjsonarray("comments");              for(int = 0; i<commentarray.length(); i++) {                 commentitem commentitem = new commentitem();                 jsonobject jsonobject;                 try {                     jsonobject = commentarray.getjsonobject(i);                      jsonobject author = jsonobject.getjsonobject("author");                     string name = author.getstring("name");                     commentitem.setcomt_name(name);                      commentitem.setcomt_imageurl(author.getstring("avatar_url"));                      simpledateformat formatdate = new simpledateformat("dd mmm, yy", locale.getdefault());                     simpledateformat formattime = new simpledateformat("hh:mm", locale.getdefault());                     simpledateformat inputformat = new simpledateformat("yyyy-mm-dd't'hh:mm:ss");                     string inputdatestr = jsonobject.getstring("date");                     log.d(tag, "comment date " + inputdatestr);                     try {                         date inputdate = inputformat.parse(inputdatestr);                         string commdatestr = formatdate.format(inputdate);                          string commtime = formattime.format(inputdate);                          commentitem.setcomt_timest(string.format(getresources().getstring(r.string.com_time_stamp), commdatestr, commtime));                     } catch (parseexception e) {                         log.d(tag, "error in parsing date");                     }                      string content = jsonobject.getstring("content");                     commentitem.setcomt_cont(content);                      mcommentitems.add(commentitem);                  } catch (jsonexception w) {                     w.printstacktrace();                 }              }           } catch (jsonexception e) {             e.printstacktrace();             comtheader.settext(r.string.comment_no);         }          madapter.notifyitemrangechanged(0, madapter.getitemcount());     }    } 

commentadapter

public class commentadapter extends recyclerview.adapter<commentadapter.viewholder> {      private imageloader mimageloader;     private context scontext;      //list of comments       @override     public commentadapter.viewholder oncreateviewholder(viewgroup parent, int viewtype) {         view v = layoutinflater.from(parent.getcontext())                 .inflate(r.layout.comment_item, parent, false);         viewholder viewholder = new viewholder(v);         return viewholder;     }      @override     public void onbindviewholder(viewholder holder, int position) {         commentitem commentitem = mcommentitems.get(position);          mimageloader = volleyrequest.getinstance(scontext).getimageloader();         mimageloader.get(commentitem.getcomt_imageurl(), imageloader.getimagelistener(holder.mimageview, r.drawable.comt_image, r.drawable.comt_name_error));          holder.mimageview.setimageurl(commentitem.getcomt_imageurl(), mimageloader);         holder.comtname.settext(commentitem.getcomt_name());         holder.comtcontent.settext(commentitem.getcomt_cont());         holder.comttimestamp.settext(commentitem.getcomt_timest());       }         public class  viewholder extends recyclerview.viewholder {         public circularnetworkimageview mimageview;         public textview comtname;         public  textview comtcontent;         public textview comttimestamp;          public viewholder(view view) {             super(view);             mimageview = (circularnetworkimageview) view.findviewbyid(r.id.comt_img);             comtname = (textview) view.findviewbyid(r.id.comt_name);             comtcontent = (textview) view.findviewbyid(r.id.comt_content);             comttimestamp = (textview) view.findviewbyid(r.id.comt_timestamp);           }     }      private list<commentitem> mcommentitems;      public commentadapter(list<commentitem> commentitems, context context) {         super();         //getting comments         this.mcommentitems = commentitems;         this.scontext = context;     }      @override     public int getitemcount() {         return mcommentitems.size();     } } 

comment_item

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"               android:orientation="vertical"               android:id="@+id/comt_item_recy"               android:layout_width="match_parent"               android:layout_height="match_parent">      <com.abdullq.commenter.circularnetworkimageview         android:layout_width="40dp"         android:layout_height="40dp"         android.alignparentleft="true"         android:id="@+id/comt_img"         android.scaletype="centercrop"         android:background="@drawable/round_button"/>     <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/comt_name"         android:layout_torightof="@+id/comt_img"         android:textstyle="bold"/>        <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/comt_content"         android:layout_below="@+id/comt_name"/>      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/comt_timestamp"         android:textstyle="italic"         android:layout_below="@+id/comt_content"/>  </relativelayout> 

frament_comment

<?xml version="1.0" encoding="utf-8"?> <linearlayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:id="@+id/comment_layout"     android:layout_width="match_parent"     android:layout_height="match_parent">       <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancemedium"         android:id="@+id/comt_head"/>       <progressbar         style="?android:attr/progressbarstylesmall"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/comt_prog"         android:indeterminate="true"/>      <android.support.v7.widget.recyclerview         android:layout_width="match_parent"         android:layout_height="match_parent"         android:id="@+id/comment_recyclerm"/> </linearlayout> 

what's confusing mprogressbar , comtheader showing why recyclerview nor displaying fetched items.

please, can tell me got wrong?

probably here:

mrecyclerview.setadapter(madapter); madapter = new commentadapter(mcommentitems, getactivity()); 

move second line before first 1 :) after second line madapter new object, attached recyclerview 1 points old one.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -