setOnCancelListener 및 setOnDismissListener는 뒤로 버튼을 누르거나 외부를 터치하는 경우 AlertDialog에 대해 호출되지 않습니다.
언제
- 대화 영역 외부를 터치합니다.
- 뒤로 버튼 누르기
onDismiss(Or onCancel)가 호출 될 것으로 예상 합니다. 그러나 둘 다 호출되지 않습니다. 내가 놓친 것이 있는지 알아도 될까요? 에서 에 AlertDialog setOnDismissListener가 작동하지 , 내가 생각 onCancel난 다시 버튼을 누를 때 호출됩니다. 그러나 그것은 나를 위해 작동하지 않습니다. 내가 놓친 것이 있는지 알 수 있습니까?
public class RateAppDialogFragment extends SherlockDialogFragment {
public static RateAppDialogFragment newInstance() {
RateAppDialogFragment rateAppDialogFragment = new RateAppDialogFragment();
return rateAppDialogFragment;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.rate_app_dialog_fragment, null);
Utils.setCustomTypeFace(view, Utils.ROBOTO_LIGHT_TYPE_FACE);
final AlertDialog dialog = new AlertDialog.Builder(this.getSherlockActivity())
.setTitle("Love JStock?")
.setView(view)
// Add action buttons
.setPositiveButton("Rate 5 stars \u2605", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Utils.showShortToast("Rate");
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Utils.showShortToast("No");
}
})
.setNeutralButton("Later", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Utils.showShortToast("Later");
}
})
.create();
dialog.setCanceledOnTouchOutside(true);
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
Utils.showShortToast("Back button pressed?");
}
});
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
// TODO Auto-generated method stub
Utils.showShortToast("Back button pressed?");
}
});
return dialog;
}
}
FragmentManager fm = fragmentActivity.getSupportFragmentManager();
if (fm.findFragmentByTag(RATE_APP_DIALOG_FRAGMENT) != null) {
return;
}
RateAppDialogFragment rateAppDialogFragment = RateAppDialogFragment.newInstance();
rateAppDialogFragment.show(fm, RATE_APP_DIALOG_FRAGMENT);
DialogFragment디스플레이에 사용할 때 문제가 발생 합니다.Dialog
에 따르면 http://developer.android.com/reference/android/app/DialogFragment.html ,이 솔루션은 무시하는 것입니다 onCancel에DialogFragment
Please take note from http://developer.android.com/reference/android/app/DialogFragment.html#onCreateDialog(android.os.Bundle) too
Note: DialogFragment own the Dialog.setOnCancelListener and Dialog.setOnDismissListener callbacks. You must not set them yourself. To find out about these events, override onCancel(DialogInterface) and onDismiss(DialogInterface).
// This is DialogFragment, not Dialog
@Override
public void onCancel(DialogInterface dialog) {
}
If you are using AlertDialog, see
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// dialog dismiss without button press
}
});
and dialog.setCanceledOnTouchOutside(true) (thanks @LeosLiterak)
You have not set backPressed key event
dialog.setOnKeyListener(new Dialog.OnKeyListener() {
@Override
public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
}
return true;
}
});
you should read this topic: How to dismiss the dialog with click on outside of the dialog?
Dialog dialog = new Dialog(context)
dialog.setCanceledOnTouchOutside(true);
in your DialogFragment, override
@Override
public void onStop() {
super.onStop();
if (mListener != null) {
// do something here
}
}
'Program Club' 카테고리의 다른 글
| 터미널을 사용하여 파일 이름을 일괄 적으로 변경하려면 어떻게해야합니까? (0) | 2020.12.14 |
|---|---|
| Javascript / jQuery : 낙타 문자 문자열을 분할하고 공백 대신 하이픈 추가 (0) | 2020.12.14 |
| 원격 저장소에 변경 사항을 푸시 할 때이 Git 경고 메시지는 무엇입니까? (0) | 2020.12.14 |
| LPARAM 및 WPARAM의 정의는 무엇입니까? (0) | 2020.12.14 |
| 파이썬에서 문자열에서 ° 문자를 얻는 방법은 무엇입니까? (0) | 2020.12.14 |