Fragment与Bundle传值

//FragmentManager
public void fmtest(Fragment ff){
fm=getSupportFragmentManager();
FragmentTransaction beginTransaction = fm.beginTransaction();
beginTransaction.replace(R.id.fl, ff);
beginTransaction.commit();

}








btn1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
FragmentTest ft=new FragmentTest();
Bundle bundle=new Bundle();
bundle.putSerializable("tt", listmr);
ft.setArguments(bundle);
fmtest(ft);

}
});






//Fragment的适配器
public class FragmentTest extends Fragment{

List<Item> item;

@Override
public void onCreate(Bundle savedInstanceState) {
Bundle bundle=getArguments();
item=(List<Item>) bundle.getSerializable("tt");

super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v=View.inflate(getActivity(), R.layout.fragment, null);
ListView lv=(ListView) v.findViewById(R.id.lv1);
MyBaseAdapter adapter=new MyBaseAdapter(getActivity(), item);
lv.setAdapter(adapter);
return v;
}

}
阅读更多
上一篇ViewPager+Fragment滑动或者点击导航颜色变化
下一篇侧滑
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭