Paul Joiner Paul Joiner - 1 year ago 140
Android Question

Error displaying content of RecyclerView (loads blank screen)

I'm very new to Android development but I am trying to build a simple app with a RecyclerView. I've followed instructions from a few different tutorials but whenever I launch the app, all I get is an empty white screen. Any ideas on where I might be going wrong? Am I missing some code? Thank you in advance.

Here is my RecyclerViewAdapter:

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.Collections;
import java.util.List;

public class Recycler_View_Adapter extends RecyclerView.Adapter<View_Holder> {
List<Data> list = Collections.emptyList();
Context context;
public View_Holder onCreateViewHolder(ViewGroup parent, int viewType) {
//Inflate the layout, initialize the View Holder
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_layout, parent, false);
View_Holder holder = new View_Holder(v);
return holder;
public void onBindViewHolder(View_Holder holder, int position) {

//Use the provided View Holder on the onCreateViewHolder method to populate the current row on the RecyclerView

public int getItemCount() {
//returns the number of elements the RecyclerView will display
return list.size();
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
// Insert a new item to the RecyclerView on a predefined position
public void insert(int position, Data data) {
list.add(position, data);
// Remove a RecyclerView item containing a specified Data object
public void remove(Data data) {
int position = list.indexOf(data);


Here is the code for my MainActivity

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {
private RecyclerView mRecyclerView;
private List<Data> data;

protected void onCreate(Bundle savedInstanceState) {

List<Data> data = fill_with_data();

Recycler_View_Adapter adapter = new Recycler_View_Adapter();
mRecyclerView = (RecyclerView) findViewById(;
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

public List<Data> fill_with_data() {

List<Data> data = new ArrayList<>();

data.add(new Data("FTWT item", "ftwt item description ", R.drawable.ftwt1));
data.add(new Data("Ftwt item 2", "ftwt item2 description ", R.drawable.ftwt2));
data.add(new Data("ftwt merch", "ftwt merch description", R.drawable.ftwt_merch1));
data.add(new Data("luca item 1", "luca item1 description", R.drawable.luca1));
data.add(new Data("luca merch1", "luca merch1 description", R.drawable.luca_shirt1));
data.add(new Data("luca merch2", "luca merch2 item description ", R.drawable.luca_shirt2));

return data;

Answer Source

You don't seem to pass data to your adapter.

Change this

Recycler_View_Adapter adapter = new Recycler_View_Adapter();


Recycler_View_Adapter adapter = new Recycler_View_Adapter(data);

In your Recycler_View_Adapter list is always empty right now. Add a constructor to accept data:

public Recycler_View_Adapter(List<Data> data){
    list = data;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download