Android进阶之Fragment和Activity之间通过setArguments传递复杂参数

1 在Activity中

 /** * 订单Fragment适配器 * Crey chenliguan on 16/4/29. */
    public class OrderorFragmentAdapter extends FragmentPagerAdapter {

        final String[] tabs;

        public OrderorFragmentAdapter(FragmentManager fm,Context context) {
            super(fm);
            tabs = context.getResources().getStringArray(R.array.order_type);
        }

        @Override
        public int getCount() {
            return tabs.length;
        }

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                PaidFragment paidFragment = new PaidFragment();
                Bundle bundle = new Bundle();
                bundle.putString(Constant.INTENT_DATA, "11");
                paidFragment.setArguments(bundle);
                return paidFragment;
            } else if (position == 1) {

            } else if (position == 2) {

            } else {
                return null;
            }
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tabs[position];
        }
    };

2 在Fragment中

Bundle bundle = getArguments();
String orderstatus = bundle.getString(Constant.INTENT_DATA);

你可能感兴趣的:(android)