我正在按照教程在ViewPagerIndicator库制作的标签栏中获取图标,但它们没有显示出来。出现标题,并调用getIconsResId方法,但无法看到图标。
这是我用于PageAdapter类的代码。它几乎是库中示例文件的精确副本。
public class IconsPagerAdapter extends FragmentPagerAdapter implements IconPagerAdapter {
protected static final String[] CONTENT = new String[] { "This", "Is", "A", "Test", };
protected static final int[] ICONS = new int[] {
R.drawable.guest,
R.drawable.home,
R.drawable.group,
R.drawable.leaderboard
};
private int mCount = CONTENT.length;
public IconsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return ViewItemTabsActivity.PlaceholderFragment.newInstance(position+1);
}
@Override
public int getCount() {
return mCount;
}
@Override
public CharSequence getPageTitle(int position) {
System.out.println("Got called");
return IconsPagerAdapter.CONTENT[position % CONTENT.length];
}
@Override
public int getIconResId(int index) {
System.out.println("This one also got called");
return ICONS[index % ICONS.length];
}
public void setCount(int count) {
if (count > 0 && count <= 10) {
mCount = count;
notifyDataSetChanged();
}
}
}
这是我编写的用于创建适配器和指示符的代码:
mSectionsPagerAdapter = new IconsPagerAdapter(faActivity.getSupportFragmentManager());
mViewPager.setAdapter((PagerAdapter) mSectionsPagerAdapter);
TabPageIndicator titleIndicator = (TabPageIndicator)llLayout.findViewById(R.id.titles);
titleIndicator.setViewPager(mViewPager);
非常感谢任何帮助。
修改
这是llLayout变量的XML。请注意,它实际上不是线性布局,而是ViewPager(我知道它不是变量的明亮名称)。
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.groupproject.sharingapp.ViewItemTabsActivity">
<com.viewpagerindicator.TabPageIndicator
android:id="@+id/titles"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</android.support.v4.view.ViewPager>