2017-08-18 36 views
1

我需要一些幫助來區分ondismiss來自哪裏。 我使用了兩個不同的dialogfragments。一種區分對話框片段OnDismiss的方法 - Android Studio

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


public void onDismiss(DialogInterface dialogInterface){ 

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

) 

有沒有辦法讓這個工作?

感謝

回答

0

如果兩個是不同類型的檢查與}這種。

if(dialogInterface instanceOf DialogInteface1){} 
+0

我試過這兩個我的對話框,但都沒有工作。 – AlWooz

+0

是不同的類(並且不相互繼承)? –

+0

是的,它們是完全不同的類,見下文。 – AlWooz