Android-----DialogFragment的使用

一、DialogFragment是Android针对一些常用场景,对Fragment进行的一次封装。

建立一个类继承DialogFragment,创建一个方法,该方法返回Fragment自身,并且保存住外界传入的类型,
public static MyDialogFragment getInstance(int type){
 MyDialogFragment f1=new MyDialogFragment ();
 Bundle bundle=new Bundle()'
 bundler.putInt("Dialog_Type",type);
 f1.setArgument(bundler);
 return f1;
}
//在onCreateDialog中写入自己的业务逻辑,当前要实现的是根据外部传入的类型,创建不同的Fragment
Dialog onCreateDialog(Bundle saveInstance){
 Dialog dialog=null;
 int dialogType=
 getArguments().getInt("Dialog_Type")//拿到通过getInstance方法保存在自身中的值
 switch(dialogType){
  case XX:
    return new AlertDialog()......
  break;
}
 return dialog;
}

在Activity中调用

MyFragment myFragment=MyFragment.getInstance();
if(myFragment!=null){
 myFragment.show(getFragmentManager(),tag);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值