AlertDialog
을 생성하는 AlertDialogUtils
클래스가있어서 오류가 발생했을 때 어떤 액티비티에서도 호출 할 수 있습니다. 문제는 createDialog()
메서드 내에서 finish()
을 onClickListener
으로 "dismiss"버튼으로 호출 할 수 없다는 것입니다.사용자 정의 대화 상자에서 활동을 닫는 방법 클래스?
어떤 생각이 가능할까요? AlertDialogUtils 클래스
코드 :
public class AlertDialogUtils extends Dialog {
private Context mContext;
public AlertDialogUtils(Context context) {
super(context);
mContext = context;
}
public void CreateAlertDialog(String errorMessage) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setMessage(errorMessage)
.setCancelable(true)
.setNeutralButton("Dismiss", new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mContext.finish();
//error here. Intend to close the activtiy that created this dialog and has the error
}
});
AlertDialog alert = builder.create();
alert.setOwnerActivity((Activity)mContext);
// The dialog utils is outside an activity. Need to set owner
alert.show();
}
}
mContext.finish() : 또한, 내가
exitActivity()
를 호출하는 대신 닫고 싶지 않았다 활동을 위해, 나는dialog.cancel()
라고? –아마도 이것이 가장 직접적인 방법은 아니지만, 액티비티를 매개 변수로 'CreateAlertDialog (String)'에 전달하지 않으시겠습니까? – Brian