I saw similar questions, did not find the answer to my own. Or I look not there. The problem itself is very simple - the application loads the data and after that it should display from the RecyclerView list. At the same time, nothing is displayed. No errors, just complete all the processes and silence. Before that I used ListView on the same data, everything was displayed. Adapter Code:

package com.artemonre.biblio; 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.ImageView; import android.widget.TextView; import java.util.ArrayList; import static com.artemonre.biblio.PlayerActivity.LOG_TAG; public class NewBiblioAdapter extends RecyclerView.Adapter <NewBiblioAdapter.ViewHolder> { ArrayList <Book> books; public static class ViewHolder extends RecyclerView.ViewHolder { TextView name; TextView author; TextView length; ImageView icon; ImageView bookType; ImageView bookFace; public ViewHolder (View view) { super (view); Log.d (LOG_TAG, "ViewHolder create"); this.name = view.findViewById (R.id.name); this.author = view.findViewById (R.id.author); this.length = view.findViewById (R.id.length); this.icon = view.findViewById (R.id.icon); this.bookType = view.findViewById (R.id.bookType); } } public NewBiblioAdapter (ArrayList <Book> books) { this.books = books; Log.d (LOG_TAG, "Adapter create"); Log.d (LOG_TAG, "book 1 = " + books.get (0)); } @Override public NewBiblioAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { Log.d (LOG_TAG, "adapter OnCreate viewHolder"); View v = LayoutInflater.from (parent.getContext()).inflate(R.layout.list_item, parent, false); ViewHolder vh = new ViewHolder (v); return vh; } @Override public void onBindViewHolder(NewBiblioAdapter.ViewHolder holder, int position) { Log.d (LOG_TAG, "bind viewHolder"); holder.name.setText (books.get (position).getName()); holder.author.setText (books.get (position).getAuthor()); if (books.get (position) instanceof AudioBook) { holder.icon.setBackgroundResource (R.drawable.iconaudio); holder.bookType.setBackgroundResource (R.drawable.typeaudio); holder.length.setText (books.get (position).getLength() + " минут"); } else { holder.icon.setBackgroundResource (R.drawable.icontext); holder.bookType.setBackgroundResource (R.drawable.typetext); holder.length.setText (books.get (position).getLength() + " страниц"); } } @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); } @Override public int getItemCount() { return 0; } } 

This is the initialization code for View and adapter assignment: Fields

 private RecyclerView recyclerView; private NewBiblioAdapter adapter; private RecyclerView.LayoutManager layoutManager; {... recyclerView = findViewById (R.id.recyclerView); layoutManager = new LinearLayoutManager (ListActivity.this); recyclerView.setLayoutManager (layoutManager); adapter = new NewBiblioAdapter ((ArrayList<Book>) books); recyclerView.setAdapter (adapter); ...} 

Before this, I get the data in AsinkTask, the adapter is assigned in onPostExecute. Thanks in advance for any help.

  • I do not see the recyclerView.notifyDataSetChanged () method; After recyclerView.setAdapter (adapter); After all, you need to update your recyclerView - Vitaly Robinovsky
  • Thank you for your help. True, in my case it does not work - I did not even find such a method. However, the view is not updated, but created from scratch, so it works without it. - Artyom Balsan

1 answer 1

Method in NewBiblioAdapter :

 @Override public int getItemCount() { return books.size(); } 

This method should return the size of the sheet that you put in the adapter ... If there is 0, nothing will be drawn.

  • E-my. Nowhere has it been stated that this is important. And he did not think at all. Thank you very much, it all worked. :) - Artyom Balzan