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

来源:互联网 发布:b21轰炸机 知乎 编辑:程序博客网 时间:2024/04/30 06:16

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);
0 0