我尝试在我的选项卡栏中添加一个新片段并执行以下操作,就像我之前为片段所做的那样: 我创建了一个片段及其布局 2.我在MainActivity中添加了片段名称:
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
switch (position) {
case 0:
locations_fragment loc = new locations_fragment();
return loc;
case 1:
qr_code qra = new qr_code();
return qra;
case 2:
HTW_Fragment htw = new HTW_Fragment();
return htw;
case 3:
Events_Fragment pre = new Events_Fragment();
return pre;
default:
return null;
}
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "Locations";
case 1:
return "QR Code Scanner";
case 2:
return "HTW";
case 3:
return "Events";
}
return null;
}
}
如果我尝试启动我的应用程序,它只显示我的标签栏中的前三个片段。
答案 0 :(得分:1)
原因其实很简单。你说适配器只有3页。 :)
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
将其替换为return 4;
并欣赏显示的第4页。