关闭

Fragment与Bundle传值

135人阅读 评论(0) 收藏 举报
//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;
}

}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3877次
    • 积分:284
    • 等级:
    • 排名:千里之外
    • 原创:26篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条