Android ViewPagerIndicator不显示标签

时间:2012-06-24 09:43:40

标签: android viewpagerindicator

我正在实施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);
}

}

1 个答案:

答案 0 :(得分:0)

ViewPagerIndicator的基于标题的指标使用getTitle(int) PagerAdapter方法返回的任何内容,该方法支持ViewPager显示标题。确保为每个页面返回非null和非空字符串。