我是android的新手,非常感谢一些帮助。
我正在尝试在我的ViewPager底部显示标签。但问题是TabLayout显示没有任何文字。
这是我在UploadActivity.java类中编写的内容
require
在XML内部,我有
public class UploadActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
ViewPager vpager = (ViewPager)findViewById(R.id.upload_viewpager);
PagerAdapter adapter = new UploadPagerAdapter(getSupportFragmentManager());
vpager.setAdapter(adapter);
}
public static class UploadPagerAdapter extends FragmentPagerAdapter{
String[] titles = new String[]{"Gallery", "Photo", "Video"};
public UploadPagerAdapter(FragmentManager manager){
super(manager);
}
@Override
public Fragment getItem(int position) {
switch(position){
case 0:
return new RestaurantListFragment();
case 1:
return new Fragment();
case 2:
return new Fragment();
}
return null;
}
@Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return titles[position];
}
@Override
public int getCount() {
return 3;
}
}
}
我已经在SOC上尝试了多个例子,但这没有帮助。请指教。
提前致谢
答案 0 :(得分:0)
在这里找到了问题:
Made string Array一个静态变量,它开始工作:
public static String[] titles = new String[]{"Gallery", "Photo", "Video"};