0

What I want to show is something like in google play. I have many product category. so I need to show it vertically, but I want the user be able to scroll product inside each category horizontal(left & right) with 2 items.

I've followed this tutorial already https://github.com/luizgrp/SectionedRecyclerViewAdapter I've change the layoutmanager to Horizontal with following code:

recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));

but it showed all sections and items horizonally.

what I want is something like the image below enter image description here

Is it possible? Please help!!

Chhorn Soro
  • 3,061
  • 8
  • 27
  • 43

1 Answers1

0

Psuedo Code:

Use Recycler View and set its layout to vertical

RecyclerView my_recycler_view = (RecyclerView) findViewById(R.id.my_recycler_view);
my_recycler_view.setHasFixedSize(true);
RecyclerViewDataAdapter adapter = new RecyclerViewDataAdapter(this, allSampleData);
my_recycler_view.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

Inside Recycler Adapter inflate the layout and set another adapter to fill in data for that layout in onBindViewHolder.Also set that layout to horizontal.

  @Override
    public ItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_item, null);
        ItemRowHolder mh = new ItemRowHolder(v);
        return mh;
    }

    @Override
    public void onBindViewHolder(ItemRowHolder itemRowHolder, int i) {

        final String sectionName = dataList.get(i).getHeaderTitle();

        ArrayList singleSectionItems = dataList.get(i).getAllItemsInSection();

        itemRowHolder.itemTitle.setText(sectionName);

        SectionListDataAdapter itemListDataAdapter = new SectionListDataAdapter(mContext, singleSectionItems);

        itemRowHolder.recycler_view_list.setHasFixedSize(true);
        itemRowHolder.recycler_view_list.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
        itemRowHolder.recycler_view_list.setAdapter(itemListDataAdapter);


        itemRowHolder.recycler_view_list.setNestedScrollingEnabled(false);

This blog has more explanation and code.

The Download link for same code given on the blog.

udit7395
  • 626
  • 5
  • 16
  • Sorry, Is this a simple recyclerview right? what I want to implement is using SectionedRecyclerViewAdapter library (https://github.com/luizgrp/SectionedRecyclerViewAdapter). we can create multiple recyclerviews. – Chhorn Soro Nov 16 '17 at 08:37
  • Do you want a Horizontal Recycler View within a Vertical Recycler View? – udit7395 Nov 16 '17 at 09:02