multithreading - Android | RecyclerView doesn't work -


i want create recyclerview few cardviews in it. start thread in oncreate of activity. there data server , put in list. create adapter recyclerview, doesn't work. here code:

here create adapter , should fill cardviews in:

listadapter adapter = new listadapter(posts); recyclerview rv = (recyclerview)findviewbyid(r.id.post_list); rv.setadapter(adapter); 

here adapter class

public class listadapter extends recyclerview.adapter<listadapter.postviewholder> {  list<post> posts;  public listadapter(list<post> posts) {     log.d("listadapter", "");     this.posts = posts; }  @override public int getitemcount() {     log.d("getitemcount", "");     return posts.size(); }  @override public postviewholder oncreateviewholder(viewgroup viewgroup, int i) {     log.d("oncreateview", "");     view v = layoutinflater.from(viewgroup.getcontext()).inflate(r.layout.insert_layout, viewgroup, false);     postviewholder pvh = new postviewholder(v);     return pvh; }  @override public void onbindviewholder(postviewholder postviewholder, int i) {     log.d("onbindview", "");     postviewholder.username.settext(posts.get(i).getusername());     postviewholder.text.settext(posts.get(i).gettext());     postviewholder.time.settext(long.tostring(posts.get(i).gettime()));     postviewholder.postphoto.setimageresource(posts.get(i).returnimg()); }  @override public void onattachedtorecyclerview(recyclerview recyclerview) {     log.d("onattached", "");     super.onattachedtorecyclerview(recyclerview); }   public static class postviewholder extends recyclerview.viewholder {     cardview cv;     textview username;     textview time;     textview text;     imageview postphoto;      postviewholder(view itemview) {         super(itemview);         log.d("postviewholder", "");         cv = (cardview) itemview.findviewbyid(r.id.cv);         username = (textview) itemview.findviewbyid(r.id.usernametext);         time = (textview) itemview.findviewbyid(r.id.timetext);         text = (textview) itemview.findviewbyid(r.id.texttext);         postphoto = (imageview) itemview.findviewbyid(r.id.postphoto);     } } 

here recyclerview:

<android.support.v7.widget.recyclerview     android:id="@+id/post_list"     android:layout_width="match_parent"     android:layout_height="match_parent">   </android.support.v7.widget.recyclerview> 

and cardview:

<android.support.v7.widget.cardview android:layout_width="match_parent"     android:layout_height="wrap_content"     android:id="@+id/cv"     xmlns:android="http://schemas.android.com/apk/res/android">          <relativelayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             >              <imageview                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/postphoto"                 android:layout_alignparentleft="true"                 android:layout_alignparenttop="true"                 />              <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:id="@+id/texttext"                 android:layout_alignparenttop="true"                 android:textsize="30sp"                 />              <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:id="@+id/usernametext"/>             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:id="@+id/timetext"/>          </relativelayout>      </android.support.v7.widget.cardview> 

and here 2 errors:

e/recyclerview: no adapter attached; skipping layout e/recyclerview: no layout manager attached; skipping layout

but both, dont't i?

set layoutmanager first.

from code :

listadapter adapter = new listadapter(posts); recyclerview rv = (recyclerview)findviewbyid(r.id.post_list); rv.sethasfixedsize(true);  linearlayoutmanager layoutmanager = new linearlayoutmanager(this); layoutmanager.setorientation(linearlayoutmanager.vertical); rv.setlayoutmanager(layoutmanager);  rv.setadapter(adapter); 

hope you!!..


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -