我在浏览器上有4页。我只想在第1页,第2页,第3页显示3个CirclePageIndicator。页面4不显示CirclePageIndicator。
mString1 = new int[]{R.string.text_guide_1, R.string.text_guide_2, R.string.text_guide_3, R.string.text_guide_10};
mString2 = new int[]{R.string.text_guide_4, R.string.text_guide_5, R.string.text_guide_6, R.string.text_guide_11};
mString3 = new int[]{R.string.text_guide_7, R.string.text_guide_8, R.string.text_guide_9, R.string.text_guide_12};
GuideAdapter adapter = new GuideAdapter(this, getContext(), mString1, mString2, mString3, this);
mPager.setAdapter(adapter);
mPager.addOnPageChangeListener(onPageChangeListener);
mCirclePageIndicator.setRadius(18);
mCirclePageIndicator.setPageColor(getContext().getResources().getColor(android.R.color.white));
mCirclePageIndicator.setFillColor(getContext().getResources().getColor(android.R.color.black));
mCirclePageIndicator.setVisibility(View.VISIBLE);
mCirclePageIndicator.setViewPager(mPager);
我的代码。它在Viewpager上显示所有CirclePageIndicator。请。救救我!
文件适配器
public class GuideAdapter extends PagerAdapter {
private LayoutInflater mInflater;
private int[] mListString1;
private int[] mListString2;
private int[] mListString3;
private Context mContext;
private CustomDialog customDialog;
public GuideAdapter(CustomDialog customDialog, Context mContext, int[] mString1, int[] mString2, int[] mString3,PageClickListener callback) {
this.customDialog = customDialog;
this.mListString1 = mString1;
this.mListString2 = mString2;
this.mListString3 = mString3;
this.mContext = mContext;
mCallback = callback;
}
public interface PageClickListener {
void onPageClick(int id);
}
private PageClickListener mCallback;
@Override
public int getCount() {
return mListString1.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}
@Override
public Object instantiateItem(ViewGroup container, final int position) {
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View imageLayout = mInflater.inflate(R.layout.item_guide, container, false);
assert imageLayout != null;
TextView text_1 = (TextView) imageLayout.findViewById(R.id.text_1);
TextView text_2 = (TextView) imageLayout.findViewById(R.id.text_2);
TextView text_3 = (TextView) imageLayout.findViewById(R.id.text_3);
text_1.setText(mListString1[position]);
text_2.setText(mListString2[position]);
text_3.setText(mListString3[position]);
text_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCallback.onPageClick(position);
}
});
text_2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCallback.onPageClick(position);
}
});
text_3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCallback.onPageClick(position);
}
});
container.addView(imageLayout, 0);
return imageLayout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
请。救救我!
答案 0 :(得分:1)
覆盖 setOnPageChangeListener ,在您的上一页中隐藏您的circleIndicator。
mPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float arg1, int arg2) {
if(position > 2) {
//hide indicator
} else if(position < 2) {
//visible indicator
}
.
.
.
答案 1 :(得分:0)
而不是添加onPageListener。只需让你的类实现ONpagechangelistener,然后取一个字段来更新当前页面位置,然后在每次更新时检查更新位置是否等于数组长度,如果它只是忽略了circularpageindicator。