Dreamers Org Dreamers Org - 4 months ago 16
Java Question

RecyclerView not showing items. Adapter is not called

So I'm sure im making some trivial mistake somewhere and just can't see it. But I am simply trying to create a basic recyclerview list. However when I run the app nothing is shown, I put in log statements and found out that the adapter is created but nothing is ever called on it (like the bindviewholder, createviewholder, or getItemsize). I am unsure what is going on. Code is below"


public class MainActivity extends GvrActivity {
private ArrayList<SampleItem> videos;
private RecyclerView recyclerView;
private SampleAdapter adapter;

protected void onCreate(Bundle savedInstanceState) {



private void intialization() {
Log.e("tree","mata intialized");
videos = new ArrayList<>();
videos.add(new SampleItem("http://vid1383.photobucket.com/albums/ah303/intellidev/congo_zpsrtmtey4l.mp4", "Adrian", 50, 100));
Log.e("tree","video added");
recyclerView = (RecyclerView) findViewById(R.id.recycle);
adapter = new SampleAdapter(this, videos);
Log.e("tree","intialization completed");


public class SampleAdapter extends RecyclerView.Adapter<SampleAdapter.ItemHolder> {
private Context context;
private ArrayList<SampleItem> items;

public SampleAdapter(Context context, ArrayList<SampleItem> videos) {

this.context = context;
this.items = videos;
Log.e("tree","adapter created");

public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.
inflate(R.layout.video_item, parent, false);
Log.e("tree","onCreateView Done");
return new ItemHolder(itemView);

public void onBindViewHolder(ItemHolder holder, int position) {
Uri uri = Uri.parse(items.get(0).getVideoUrl());
VrVideoView.Options options = new VrVideoView.Options();
options.inputType = VrVideoView.Options.TYPE_STEREO_OVER_UNDER;
try {
holder.view.loadVideo(uri, options);
} catch (IOException e) {
Log.e("tree","onBindViewError " +e.getMessage());


public int getItemCount() {
Log.e("tree","items size is "+items.size());
return items.size();

class ItemHolder extends RecyclerView.ViewHolder {
private VrVideoView view;
private Button likes;
private Button shares;
private Button profile;

public ItemHolder(View itemView) {
// Stores the itemView in a public final member variable that can be used
// to access the context from any ViewHolder instance.

view = (VrVideoView) itemView.findViewById(R.id.video_view);
likes = (Button) itemView.findViewById(R.id.likesButton);
shares = (Button) itemView.findViewById(R.id.sharesButton);
profile = (Button) itemView.findViewById(R.id.videoProfileButton);




If you want to use a RecyclerView, you will need to work with the following:

  • RecyclerView.Adapter - To handle the data collection and bind it to the view

  • LayoutManager - Helps in positioning the items

  • ItemAnimator - Helps with animating the items for common operations such as Addition or Removal of item

item animator is optional but adapter and Layoutmanager are necessary

you forgot to add layout manager. this two line of code probably solves your problem

LinearLayoutManager llm = new LinearLayoutManager(getActivity());