package ru.dyatel.tsuschedule.layout;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import ru.dyatel.tsuschedule.R;

public class MenuButtonAdapter extends RecyclerView.Adapter<MenuButtonAdapter.Holder> {

    private class MenuEntry {

        int iconResId;
        int textResId;
        Runnable action;

        public MenuEntry(int iconResId, int textResId, Runnable action) {
            this.iconResId = iconResId;
            this.textResId = textResId;
            this.action = action;
        }

    }

    private MenuEntry[] menu = new MenuEntry[]{

    };

    class Holder extends RecyclerView.ViewHolder {

        public Holder(View v) {
            super(v);
        }

    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new Holder(
                LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.menu_button, parent, false)
        );
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        final MenuEntry entry = menu[position];
        TextView button = (TextView) holder.itemView;
        button.setCompoundDrawablesWithIntrinsicBounds(
                ContextCompat.getDrawable(button.getContext(), entry.iconResId), null, null, null
        );
        button.setText(entry.textResId);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                entry.action.run();
            }
        });
    }

    @Override
    public int getItemCount() {
        return menu.length;
    }

}

@@ -286,16 +286,69 @@
 ule.R;%0A%0A
+import java.util.LinkedList;%0Aimport java.util.List;%0A%0A
 public c
@@ -741,65 +741,8 @@
  %7D%0A%0A
-    private MenuEntry%5B%5D menu = new MenuEntry%5B%5D%7B%0A%0A    %7D;%0A%0A
     
@@ -853,32 +853,168 @@
       %7D%0A%0A    %7D%0A%0A
+    private List%3CMenuEntry%3E menu = new LinkedList%3C%3E();%0A%0A    public void addMenuEntry(MenuEntry entry) %7B%0A        menu.add(entry);%0A    %7D%0A%0A
     @Override%0A  
@@ -1372,17 +1372,21 @@
 menu
-%5B
+.get(
 position
 %5D;%0A 
@@ -1385,9 +1385,9 @@
 tion
-%5D
+)
 ;%0A  
@@ -1910,14 +1910,14 @@
 enu.
-length
+size()
 ;%0A  

Rework menu adapter to use a list instead of array