How do I make a recyclerview of my appear on a tab instead of fixed on main?

0

I created a recyclerview in main that is ok, so I created 2 tabs that are ok. But when I switch between tabs the recycler view is fixed on the screen instead of just appearing on tab1. A friend told me that I needed to use context but I did not understand what this is, so does anyone have a suggestion?

 //RecyclerView

private RecyclerView recyclerView;
private RecyclerView.Adapter recyclerViewAdapter;
private RecyclerView.LayoutManager layoutManager;
String[] materias = {"Português", "Matemática", "Inglês"};
Double[] notas = {7.5, 10.0, 2.7};
Integer[] faltas = {5, 6, 3};

//Fim do RecyclerView

Now inside OnCreate

 recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
 recyclerViewAdapter = new RecyclerViewAdapter(materias, notas, faltas);
 layoutManager = new LinearLayoutManager(this);
 recyclerView.setLayoutManager(layoutManager);
 recyclerView.setHasFixedSize(true);
 recyclerView.setAdapter(recyclerViewAdapter);

Tabs

    adapter = new ViewPagerAdapter(getSupportFragmentManager(), Titles, Numboftabs);


    pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(adapter);


    tabs = (SlidingTabLayout) findViewById(R.id.tabs);
    tabs.setDistributeEvenly(true); 


    tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
        @Override
        public int getIndicatorColor(int position) {
            return ContextCompat.getColor(MainActivity.this, R.color.colorPrimary);

            }
        });

    // Setting the ViewPager For the SlidingTabsLayout
    tabs.setViewPager(pager);


}
    
asked by anonymous 12.09.2016 / 19:04

1 answer

0

Activity will contain a fragment for each tab. Each fragment will contain a recyclerview.

Structure:

-activity1|-tab1-fragment1-recyclerview1
          |-tab2-fragment2-recyclerview2

In issue of execution flow: activity_main.xml contains a widget called viewpager. In the MainActivity.class, you call the Viewpager and arrow on it an adapter. The Adapter is a special class that will contain so many fragments within it. Each snippet is an xml and a class, too. Each fragment represents the contents of a tab. Within each xml of fragments, you create a recyclerview (widget). Within each class of each fragment, you program the execution of recyclerview.

    
13.09.2016 / 15:34