Skip to content

Instantly share code, notes, and snippets.

@nein37
Last active August 29, 2015 14:04
Show Gist options
  • Save nein37/6237ab570b6d4d578e2a to your computer and use it in GitHub Desktop.
Save nein37/6237ab570b6d4d578e2a to your computer and use it in GitHub Desktop.
@Override
public void onClick(View v) {
HogeDialogFragment fragment = new HogeDialogFragment();
// 必要なパラメータがあればsetArgument
// requestCodeが37になる
fragment.setTargetFragment(null,37);
fragment.show(getFragmentManager(), "dialog");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 37)
Log.d("HogeDialogFragmentResult", Integer.toString(requestCode));
}
@Override
public void onClick(DialogInterface dialog, int which) {
Intent result = new Intent();
// 他にパラメータが必要ならこの辺で適当にputExtra
if (getTargetFragment() != null) {
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, result);
} else {
PendingIntent pi = getActivity().createPendingResult(getTargetRequestCode(), result,
PendingIntent.FLAG_ONE_SHOT);
try {
pi.send();
} catch (PendingIntent.CanceledException ex) {
// send failed
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment