Implemented RecyclerView

It seems to have done everything correctly, and there is a list from where to get the data and the template and the adapter and check everything is OK on the debager, but there is nothing on the device ... As if the invisible cost ... I don’t understand what it is ...

Here is the XML code

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/backforchat" android:orientation="vertical" tools:context=".activities.ActivityChat"> <android.support.design.widget.AppBarLayout android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbarchat" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@color/color_grew_toolbar" android:elevation="2dp"> </android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout> <android.support.v7.widget.RecyclerView android:id="@+id/rvChat" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" /> </LinearLayout> 

Here is the adapter code

 public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ChatHolder> { private List<MessagesChat> messages; public ChatAdapter(List<MessagesChat> messages) { this.messages = messages; } @Override public ChatHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.message_card, viewGroup, false); return new ChatHolder(v); } @Override public void onBindViewHolder(ChatHolder holder, int i) { MessagesChat messagesChat = messages.get(i); Bitmap bitmap = messagesChat.getPersonPhotoChat(); if (bitmap != null) { holder.ivPersonPhotoChat.setImageBitmap(bitmap); } else { holder.ivPersonPhotoChat.setImageResource(States.DEFAULT_PHOTO_ICON); } holder.tvMessageBody.setText(messagesChat.getMessageBody()); holder.tvArriveTime.setText(messagesChat.getArrivingTime()); } @Override public int getItemCount() { return messages.size(); } class ChatHolder extends RecyclerView.ViewHolder{ ImageView ivPersonPhotoChat; TextView tvMessageBody; TextView tvArriveTime; public ChatHolder(View item) { super(item); ivPersonPhotoChat = (ImageView) item.findViewById(R.id.ivPersonPhotoChat); tvMessageBody = (TextView) item.findViewById(R.id.tvMessageBody); tvArriveTime = (TextView) item.findViewById(R.id.tvArriveTime); } } @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); } } 

and here is the class itself

 public class ActivityChat extends AppCompatActivity { private Context context; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_activity_chat); context = getApplicationContext(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarchat); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); } List<MessagesChat> messages = new ArrayList<>(); for (int i = 0; i < 15; i++){ messages.add(new MessagesChat("Hello!", "14:24", null)); } RecyclerView rvChat = (RecyclerView) findViewById(R.id.rvChat); ChatAdapter adapter = new ChatAdapter(messages); rvChat.setAdapter(adapter); } 

What missed? Or how can I check?

In the class, the list is filled up and transmitted to the adapter, this is evident from the debug, the adapter accepts it, all the rules ... Why I don’t understand the picture on the screen

  • No only pictures? In the code there are no references to pictures in the data, from where it should appear - pavlofff
  • @pavlofff in the sense of no references? Maybe we are not talking about the same thing, I mean - there is no picture, in the sense that the list does not appear on the screen ... Only an empty background that I set in XML - Aleksey Timoshchenko

1 answer 1

Need to add some LayoutManager. For example, Linear:

 rvChat.setLayoutManager(new LinearLayoutManager(this)); rvChat.setAdapter(adapter);