notifyDataSetChanged适配器ViewPager不起作用

时间:2017-12-31 18:04:39

标签: android android-viewpager adapter

我的适配器ViewPager在调用notifyDataSetChanged

后无法更新

我的代码中的错误在哪里?

    public class MyObjectAdapter extends PagerAdapter {

  .....
            public MyObjectAdapter(Activity activity, ArrayList<MyObject> myObjectList) {
                this.activity = activity;
            this.data = myObjectList;
            mLayoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

    .....

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            View view = mLayoutInflater.inflate(R.layout.item_list, container, false);
            MyObject myObject = data.get(position);
            RobotoRegularTextView title = (RobotoRegularTextView) view.findViewById(R.id.title);
            title.setText(myObject.title);
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public int getItemPosition(Object object) {
            MyObject myObject = (MyObject) ((View) object).getTag();
            int position = data.indexOf(myObject);
            if (position >= 0) {
                return position;
            } else {
                return POSITION_NONE;
            }
        }

    }

0 个答案:

没有答案