I'm trying to set up a tablayout with 3 tabs, each tab will have a recycler view in it. I found this question: How to implement RecyclerView with CardView rows in a Fragment with TabLayout Which is similier to what I want, I'm trying to set this up, then I'll set up my data retrieval after I get this working.
The problem I'm getting now it setting up the PagerAdapter. Here is my code:
public class WorkoutDaysActivity extends BaseActivity{
ListView mListView = new ListView(this);
ArrayList<CustomObject> w29w1m;
CustomListViewAdapter mCustomListViewAdapter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.workout_days);
mToolBar = activateToolbar();
setUpNavigationDrawer();
// Get the ViewPager and set it's PagerAdapter so that it can display items
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
PagerAdapter pagerAdapter =
new PagerAdapter(getSupportFragmentManager(), WorkoutDaysActivity.this)
viewPager.setAdapter(pagerAdapter);
// Give the TabLayout the ViewPager
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.setupWithViewPager(viewPager);
// Iterate over all tabs and set the custom view
for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
tab.setCustomView(pagerAdapter.getTabView(i));
}
}
@Override
public void onResume() {
super.onResume();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
class PagerAdapter extends FragmentPagerAdapter {
String tabTitles[] = new String[] { "Tab One", "Tab Two", "Tab Three" };
Context context;
public PagerAdapter(FragmentPagerAdapter fm, Context context) {
super(fm);
this.context = context;
}
@Override
public int getCount() {
return tabTitles.length;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new WorkoutDetailFragment();
case 1:
return new WorkoutDetailFragment();
case 2:
return new WorkoutDetailFragment();
}
return null;
}
@Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return tabTitles[position];
}
public View getTabView(int position) {
View tab = LayoutInflater.from(WorkoutDaysActivity.this).inflate(R.layout.custom_tab, null);
TextView tv = (TextView) tab.findViewById(R.id.custom_text);
tv.setText(tabTitles[position]);
return tab;
}
}}
The first spot where I'm getting an error is
PagerAdapter pagerAdapter =
new PagerAdapter(getSupportFragmentManager(), WorkoutDaysActivity.this)
viewPager.setAdapter(pagerAdapter);
The error is:
PagerAdapter (android.support.v4.app.FragmentPagerAdapter, Context) in PagerAdapter cannot be applied to: (android.support.v4.app.FragmentManager, WorkoutDaysActivity.this)
The android.support.v4.app.FragmentManager is the part underlined in red. The second error is in this part:
class PagerAdapter extends FragmentPagerAdapter {
String tabTitles[] = new String[] { "Tab One", "Tab Two", "Tab Three" };
Context context;
public PagerAdapter(FragmentPagerAdapter fm, Context context) {
super(fm);
this.context = context;
}
The error is in the super(fm); part, and it states:
FragmentPagerAdapter (android.support.v4.app.FragmentManager) in FragmentPagerAdapter cannot be applied to: android.support.v4.app.FragmentPagerAdapter
I feel like this would be a simple error with importing the wrong thing, but my attempts to fix it failed. Any help greatly appreciated thank you!