0
I created a recyclerview on main which is ok, tbm I created 2 tabs which are ok. But when I change between tabs the Recycler view is fixed on the screen instead of just appearing in tab1. A friend told me I needed to use context but I didn’t even understand what it is, and then someone has 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 the 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);
}
Put the code you’re using, it’s better to help you
– Leonardo Dias
Ready, I put what was relevant.
– Danilo Silva
I believe you need to call recyclerView inside the Viewpager Adapter
– Icaro