Fragment复用

首先我们要先定义两个值:

private String [] aa = new String[]{"头条","科技","财经","军事"};

private String [] bb = new String[]{"http://c.m.163.com/nc/article/headline/T1348647909107/0-20.html","http://c.m.163.com/nc/article/list/T1348648756099/0-20.html","http://c.m.163.com/nc/article/list/T1348648141035/0-20.html","http://c.m.163.com/nc/article/list/T1348649079062/0-20.html"};
而后在initView()方法里for循环:
 
for (int i = 0; i <aa.length ; i++) {

mString.add(aa[i]);
//复用Fragment
BFragment bFragment = new BFragment();
//传值
Bundle bundle = new Bundle();
bundle.putString("爱你哒", bb[i]);
bFragment.setArguments(bundle);

mFragment.add(bFragment);
}
最后在另一个Fragment里面接收数据:
//获取数据
Bundle bundle = getArguments();
String string = bundle.getString("爱你哒");
mPresenter.loginPre(string);

你可能感兴趣的:(Fragment复用)