Q:

how to make group items in recyclerview using header

I want to set group header in recyclerview,which means i have an api which contains json objects based on Lessons for example Lesson1 contains more than 3 items Lesson 2 contains 4 items.I already got response from api and displayed into recyclerview like this.
Lesson 1:
Lesson 1:Random Numbers
Lesson 1:Complex Numbers
Lesson 1:Matrix

-
Lesson 2:
Lesson 2:Algebra
Lesson 2:Differentiation
Lesson 2:Integration 

Like this i displayed into recyclerview .I want to group header display like
Lesson 1:
Random Numbers
Complex Numbers
Matrix

-
Lesson 2:
Algebra
Differentiation
Integration 

want to set header and group the items please help me frnds

A:

With the library SectionedRecyclerViewAdapter you can group your items in sections and add a header to each section:
class MySection extends StatelessSection {

    String title;
    List<String> list;

    public MySection(String title, List<String> list) {
        // call constructor with layout resources for this Section header, footer and items 
        super(R.layout.section_header, R.layout.section_footer,  R.layout.section_item);

        this.title = title;
        this.list = list;
    }

    @Override
    public int getContentItemsTotal() {
        return list.size(); // number of items of this section
    }

    @Override
    public RecyclerView.ViewHolder getItemViewHolder(View view) {
        // return a custom instance of ViewHolder for the items of this section
        return new MyItemViewHolder(view);
    }

    @Override
    public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyItemViewHolder itemHolder = (MyItemViewHolder) holder;

        // bind your view here
        itemHolder.tvItem.setText(list.get(position));
    }

    @Override
    public RecyclerView.ViewHolder getHeaderViewHolder(View view) {
        return new SimpleHeaderViewHolder(view);
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {
        MyHeaderViewHolder headerHolder = (MyHeaderViewHolder) holder;

        // bind your header view here
        headerHolder.tvItem.setText(title);
    }
}

Then you set up the RecyclerView with your Sections:
// Create an instance of SectionedRecyclerViewAdapter 
SectionedRecyclerViewAdapter sectionAdapter = new SectionedRecyclerViewAdapter();

MySection lesson1Section = new MySection("Lesson 1", lesson1List);
MySection lesson2Section = new MySection("Lesson 2", lesson2List);

// Add your Sections
sectionAdapter.addSection(lesson1Section);
sectionAdapter.addSection(lesson2Section);

// Set up your RecyclerView with the SectionedRecyclerViewAdapter
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(sectionAdapter);

