FragmentStatePagerAdapter 向 TextView 返回错误的位置

FragmentStatePagerAdapter returning wrong position to TextView

好的,我有一个 Activity,其中有 viewpager 和 textview。然后我有扩展 FragmentStatePagerAdapter 的适配器,这里是它的代码:

public AdapterCustomPage(FragmentManager fm, Context context, TextView TV ) {
        super(fm);
        mContext = context;
        mTV = TV;
    }

    @Override
    public Fragment getItem(int position) {

        // Create fragment object
        Fragment fragment = new ImageFragmentKatalozi();
        Bundle args = new Bundle();
        Log.i("Poizicija" , String.valueOf(position));
        String url = Static.katalozi.getSlikeKataloga().get(position);
        args.putString("url", url);

        fragment.setArguments(args);



        mTV.setText(String.valueOf(position + 1) + "/" + String.valueOf(maxBrojStrana));

        String link = Static.katalozi.getUrl();
        args.putString("linkKataloga", link);

        if(position == 0){
            Message.message(mContext, "Na prvoj stranici kataloga ste");
        }
        if(position == getCount() - 1){
            Message.message(mContext, "Na poslednjoj stranici kataloga ste");
        }


        return fragment;
    }


    @Override
    public int getItemPosition(Object object) {
        pozicija = super.getItemPosition(object);
        return super.getItemPosition(object);
    }

    @Override
    public int getCount() {
        return maxBrojStrana;
    }

最后我有了片段:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_katalozi_slike, container, false);

        args = getArguments();
        imageView = (TouchImageView) rootView.findViewById(R.id.imageViewAdapterZaListanjeKataloga);
        Picasso.with(getActivity()).load(args.getString("url")).placeholder(R.drawable.load).error(R.drawable.error).into(imageView);



        return rootView;
    }

现在,问题是,我在主 activity 中的 TextView 没有返回片段的正确位置。它提供了良好的 getCount 位置,但是当我向右滑动时它变为 + 1,当我向左滑动时它下降到 0。当我将整个 textView 代码和 xml 放在片段部分时,它效果很好,但随后会随着片段滑动。有帮助吗?

mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                brojStranica.setText(String.valueOf(position + 1) + "/" + String.valueOf(Static.katalozi.getSlikeKataloga().size()));
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });