android recyclerview doesn't display items
In MainActivity
ArrayList<String> list = new ArrayList<>();
list.add("something1");
list.add("something2");
RecyclerView recyclerView = (RecyclerView)findViewById(R.id.rec);
recyclerView.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(linearLayoutManager);
MenuRecAdapter menuRecAdapter = new MenuRecAdapter(list);
recyclerView.setAdapter(menuRecAdapter);
RecyclerView Adapter
public class MenuRecAdapter extends RecyclerView.Adapter<RecViewHolder>{
private ArrayList<String> mList = new ArrayList<>();
Activity context;
public MenuRecAdapter(ArrayList<String> mList){
this.mList = mList;
}
public int getItemCount(){
return mList.size();
}
public RecViewHolder onCreateViewHolder(ViewGroup viewGroup, int position){
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.menuitem, viewGroup, false);
RecViewHolder pvh = new RecViewHolder(v);
return pvh;
}
public void onBindViewHolder(RecViewHolder holder, int i){
holder.menuTeXT.setText(mList.get(i));
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
}
and ViewHolder remains same...
public class RecViewHolder extends RecyclerView.ViewHolder {
public TextView menuTeXT;
public RecViewHolder(View itemView){
super(itemView);
menuTeXT = (TextView)itemView.findViewById(R.id.menuTXT);
}
}
also get rid of MenuData class. The above code should work fine.