gabi
gabi

Reputation: 1

Multiple recycler views with different layouts

I have a problem with dynamic creation of recyclerView with different layouts. I want to have some objects in horizontal orientation and remaining in vertical. Both are recyclerView. Below code, what I have:

parentLayout = new RelativeLayout(getContext());

RelativeLayout.LayoutParams layoutParams = new 
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 
RelativeLayout.LayoutParams.MATCH_PARENT);

for (Map.Entry<Integer, ArrayList<Object>> entry : items.entrySet()) {
adapter = new CustomAdapter(getContext(), entry.getValue())
View view = inflater.inflate(R.layout.recycler, container, false);
if (view instanceof RecyclerView) {
      recyclerView = (RecyclerView) view;
      CustomLayout cl = new CustomLayout();
      LinearLayoutManager lm = new LinearLayoutManager(getContext());
      recyclerView.setAdapter(adapter);
      recyclerView.setItemAnimator(null);
      recyclerView.setLayoutManager(ifSomething ? cl : lm);
    }
   parentLayout.addView(view, layoutParams);
}

At this moment, I receive multiple recycleView overlapping, and I just want to add up them under the other.

Upvotes: 0

Views: 59

Answers (1)

Bram Jongebloet
Bram Jongebloet

Reputation: 336

Uhm I don't think u want to implement multiple recyclerviews. You only need to implement one recyclerview and create 2 viewholders one with a horizontal linearlayout and one with a vertical linearlayout. Add an adapter to your recyclerview which manages the items of your list and convert them to the right viewholder for your recyclerview. Recyclerviews are only used for showing a list with multiple items. There not really meant to be shown as multiple views.

Please follow the steps in this link: https://developer.android.com/guide/topics/ui/layout/recyclerview

Upvotes: 1

Related Questions