- dotykowy poza regionem dialogowym
- Naciśnij przycisk na tylnym
Czekam onDismiss
(Lub onCancel
) zostanie wywołana. Jednak obaj nie są powołani. Czy mogę wiedzieć, że jest coś, czego mi brakuje? Od AlertDialog setOnDismissListener not working, myślałem, że onCancel
zostanie wywołany po naciśnięciu przycisku Wstecz. Ale to nie działa dla mnie. Czy mogę wiedzieć, czy coś tam przeoczyłem?
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);
@pskink Czy testowych uruchomić na kodzie? To naprawdę działa dobrze dla ciebie? –
Używam Log.d. Nie inny. Ani toast, ani komunikat logowania nie są wyświetlane. –
uruchamiam go z minimalną konfiguracją - Builder z tylko dodatnimi i ujemnymi przyciskami, testowany z 2.2 avd – pskink