【问题标题】:A way to differentiate OnDismiss from dialogfragment - Android Studio一种区分 OnDismiss 和 dialogfragment 的方法 - Android Studio
【发布时间】:2017-08-18 07:24:59
【问题描述】:

我需要一些帮助来以某种方式区分 ondismiss 的来源。 我正在使用两个不同的对话片段。

DialogClass1 dialog1 = new DialogClass1();
DialogClass2 dialog2 = new DialogClass2();


public void onDismiss(DialogInterface dialogInterface){

    if(dialogInterface.equals(dialog1){
         //CODE#
    }else if(dialogInterface == dialog2){
         //CODE#
    }

  )

有没有办法让它工作?

谢谢

【问题讨论】:

    标签: java android dialog fragment


    【解决方案1】:

    如果两者属于不同类型,请使用 instanceOf 进行检查。

    if(dialogInterface instanceOf DialogInteface1){}
    

    【讨论】:

    • 我用我的两个对话框都试过了,但都没有。
    • 是不同的类(并且不相互继承)吗?
    • 是的,它们是完全不同的类,见下文。
    • 公共类 DialogClass1 扩展 DialogFragment 实现 DialogInterface.OnDismissListener
    • 公共类 DialogClass2 扩展 DialogFragment 实现 DialogInterface.OnDismissListener
    猜你喜欢
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多