In order to implement sliding tabs in Android, i am following this guide: Google Play Style Tabs using TabLayout
At the point of implement the FragmentPageAdapter i am having a problem whith the "getItem()" method which is supossed to return the fragment with the associated position, in this case "PageFragment.newinstance(position + 1)". Being PageFragment a generic Fragment. The problem itself is:
'getItem(int)' in 'com.myProject.SampleFragmentPagerAdapter' clashed with 'getItem(int)' in 'android.support.v4.app.FragmentPagerAdapter'; attempting to use incompatible return types
Can someone figure out where the problem is?
I have attached the SampleFragmentPagerAdapter of the guide for faster checks:
public class SampleFragmentPagerAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 3;
private String tabTitles[] = new String[] { "Tab1", "Tab2", "Tab3" };
private Context context;
public SampleFragmentPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
}
@Override
public int getCount() {
return PAGE_COUNT;
}
@Override
public Fragment getItem(int position) {
return PageFragment.newInstance(position + 1);
}
@Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return tabTitles[position];
}
}