Created
August 4, 2014 10:23
-
-
Save nein37/fb85b63044e8c749f29e to your computer and use it in GitHub Desktop.
DialogFragmentのコールバック ref: http://qiita.com/nein37/items/75fcec3ab07f00f6936a
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 | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
// 指定したrequestCodeで戻ってくる | |
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) { | |
// 呼び出し元がFragmentの場合 | |
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, result); | |
} else { | |
// 呼び出し元がActivityの場合 | |
PendingIntent pi = getActivity().createPendingResult(getTargetRequestCode(), result, | |
PendingIntent.FLAG_ONE_SHOT); | |
try { | |
pi.send(Activity.RESULT_OK); | |
} catch (PendingIntent.CanceledException ex) { | |
// send failed | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment