页面的建立(二)

下面用到了部分XUtils的ViewUtils,UI绑定和时间的绑定

public class ContentFragment extends BaseFragment {
   <!--这句是不用find ID-->
    @ViewInject(R.id.rg_rb)
    private RadioGroup radioGroup;

    @ViewInject(R.id.vp_content)
    private ViewPager viewPager;

    private ArrayList<BasePager> mPagerList;

    @Override
    public View initViews() {
        View view = View.inflate(mActivity, R.layout.fragment_content, null);
        // radioGroup = (RadioGroup) view.findViewById(R.id.rg_rb);
         <!--这句是对事件的注入-->
        ViewUtils.inject(this, view);

        return view;
    }

    @Override
    public void initData() {
        radioGroup.check(R.id.rb_home);//默认勾选首页
        //初始化5个子页面
        mPagerList = new ArrayList<>();



        mPagerList.add(new HomePager(mActivity));
        mPagerList.add(new NewsPager(mActivity));
        mPagerList.add(new SmartPager(mActivity));
        mPagerList.add(new GovPager(mActivity));
        mPagerList.add(new SettingPager(mActivity));




        viewPager.setAdapter(new ContentAdapter());

    }

    class ContentAdapter extends PagerAdapter {
        @Override
        public int getCount() {
            return mPagerList.size();
        }
        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            BasePager pager = mPagerList.get(position);
            container.addView(mPagerList.get(position).mRootView);
            pager.initData();//初始化数据
            return mPagerList.get(position).mRootView;
        }
        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    }
}

传承者(Inheritors)欢迎各位纠正错误,评论,吐槽!!!

你可能感兴趣的:(页面的建立(二))