RecyclerView not showing

I have a RecyclerView that does not display any elements. It is initially empty, but later I add elements and call notifyDatasetChanged (). getItemCount () is called and returns 25, onBindViewHolder is called 3 times and sets the view correctly.

public AlbumListAdapter(FacebookActivity activity, long pageId, OnItemClickListener listener){ this.listener = listener; this.inflater = LayoutInflater.from(activity); this.service = new PagedGraphService<Album>(String.format("https://graph.facebook.com/%d/albums", pageId), new PagedGraphService.ServiceUpdateListener() { @Override public void dataUpdated() { notifyDataSetChanged(); } @Override public void endReached() { } }, new TypeToken<PagedGraphService.GraphResponse<Album>>(){}.getType()); } @Override public AlbumHolder onCreateViewHolder(ViewGroup viewGroup, int i) { return new AlbumHolder(inflater.inflate(R.layout.photo_album_list_card, viewGroup, false)); } @Override public void onBindViewHolder(AlbumHolder viewHolder, int i) { viewHolder.setAlbum(service.get(i)); } @Override public int getItemCount() { return service.getLoadedCount(); } 

The essence of it. The service contains a list of albums and notifies the adapter of changes by calling dataUpdated () and endReached ().

More code:

 @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { RecyclerView view = (RecyclerView) inflater.inflate(R.layout.recycler, container, false); view.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)); view.setHasFixedSize(false); AlbumListAdapter adapter = new AlbumListAdapter(activity, FacebookActivity.PSM_PAGE_ID, this); view.setAdapter(adapter); return view; } <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v7.widget.RecyclerView> 

More code:

Action layout

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/toolbar"/> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> 

List Layout:

 <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/album_list_title" android:layout_width="match_parent" android:layout_height="match_parent"/> </android.support.v7.widget.CardView> 

Layout List:

 <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v7.widget.RecyclerView> 

I stuck behind the code for several hours, and I have no idea why it doesn't work.

+8
android android-recyclerview
source share
1 answer

I am an idiot.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/toolbar"/> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> 

The default orientation for LinearLayout horizontal and the width of the toolbar is match_parent , so my content is disabled. This is probably one of the most popular errors in android, so you get a warning, but include must have hidden it.

+21
source share

All Articles