1.在viewpager适配器中传值
vp.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
@Override
public CharSequence getPageTitle(int position) {
return titles.get(position);
}
@Override
public Fragment getItem(int position) {
FFF1 fff1 = new FFF1();
Bundle bundle = new Bundle();
bundle.putString("ming",titles.get(position));
fff1.setArguments(bundle);
return fff1;
}
@Override
public int getCount() {
return titles.size();
}
});
tab.setupWithViewPager(vp);
vp.setOffscreenPageLimit(titles.size());
2.接收并判断然后拼接
String name = getArguments().getString("ming","");
if (name!=null){
String getname = getname(name);
getdata.getdatafromnet(getActivity(), "http://mnews.gw.com.cn/wap/data/news/"+getname+"/page_1.json", new Callback() {
@Override
public void getsjson(String json) {
try {
Log.d("TAG","++++++++++++++++++"+json);
Gson gson = new Gson();
Type type = new TypeToken<List<Bean>>() {}.getType();
List<Bean> data = gson.fromJson(json, type);
for (Bean b:data) {
data1.addAll(b.getData());
}
lv.setAdapter(new Listadapter(getActivity(),data1));
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
判断
private String getname(String name){
String str="";
if (name.equals("数据新闻")){
str="xbsjxw";
}else if (name.equals("快讯")){
str="txs";
}else if (name.equals("头条")){
str="toutiao";
}else if (name.equals("精编公告")){
str="news/mobile/jbgg";
}else if (name.equals("美股")){
str="news/mobile/mgxw";
}else if (name.equals("港股")){
str="news/mobile/ggxw";
}else if (name.equals("基金")){
str="news/mobile/jjxw";
}else if (name.equals("理财")){
str="news/mobile/lcxw";
}
return str;
}