我正在实施ViewPagerIndicator,例如:http://blog.stylingandroid.com/archives/537
除了我的指示器没有显示我正在设置的标签外,一切都没问题。这是我如何设置它们:
公共类MainPagerActivity扩展了Activity {
private ViewPager pager;
private List<View> pages;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewpager_main);
initUI();
}
private void initUI() {
LayoutInflater inflater = LayoutInflater.from(this);
pager = (ViewPager)findViewById(R.id.main_pager);
pages = new ArrayList<View>();
pager.setCurrentItem(0);
ListView all = (ListView)inflater.inflate(R.layout.all_thoughts, null);
all.setTag("All thoughts");
pages.add(all);
ListView favorites = (ListView)inflater.inflate(R.layout.all_thoughts, null);
favorites.setTag(R.string.favorites);
pages.add(favorites);
RelativeLayout profile = (RelativeLayout)inflater.inflate(R.layout.profile, null);
profile.setTag(R.string.profile);
pages.add(profile);
ViewPagerAdapter adapter = new ViewPagerAdapter(pages);
pager.setAdapter(adapter);
TitlePageIndicator titleIndicator = (TitlePageIndicator)findViewById(R.id.indicator);
titleIndicator.setViewPager(pager);
titleIndicator.setCurrentItem(0);
}
}
答案 0 :(得分:0)
ViewPagerIndicator的基于标题的指标使用getTitle(int)
PagerAdapter
方法返回的任何内容,该方法支持ViewPager
显示标题。确保为每个页面返回非null
和非空字符串。