在我的MainActivity中,我在viewpager中有一個片段。在這個片段中我建立了一個自定義對話框自定義對話框可以在從MainActivity調用的其他片段中正常取消。但是,在這個片段中,它不能被取消。我不知道我的對話發生了什麼。請幫我檢查下面的代碼。提前致謝。Android:無法在viewpager中的片段中取消自定義對話框
dialog = new Dialog(getActivity(), R.style.CustomDialogTheme);
dialog.setContentView(R.layout.popup_login_sns);
LinearLayout cancelButton = (LinearLayout) dialog.findViewById(R.id.cancelButtonSNS);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("GETBOOKMARK", "call dialog cancel");
dialog.cancel();
}
});
dialog.show();
我也嘗試使用解僱()函數,但沒有任何變化。我無法關閉對話框。 –
看到我編輯的答案,我用取消按鈕,它的工作。你應該有'cancelButtonSNS',即'''LinearLayout cancelButton =(LinearLayout)dialog.findViewById(R.id.cancelButtonSNS)'''popup'login_sns.xml'' – Kathi
非常感謝,我可以關閉對話框。問題是我用來創建對話框的上下文。我在對話框的上下文中犯了一個錯誤。 –