我在分页器上有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);
}


请。帮我!

最佳答案

覆盖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
        }

    .
    .
    .

09-13 01:22