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);
}