Last active
August 29, 2015 14:04
-
-
Save nein37/6237ab570b6d4d578e2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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