この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
|
dialogfragmentを使ったカスタムダイアログ [2015/02/25 11:35] sou [Dialogから親Activityにコールバックを返す] |
dialogfragmentを使ったカスタムダイアログ [2015/02/25 15:30] (現在) sou [Dialogの表示] |
||
|---|---|---|---|
| ライン 53: | ライン 53: | ||
| ===== Dialogの表示 ===== | ===== Dialogの表示 ===== | ||
| - | タグやリクエストコードなどはonActivityResultやDialog側でも使用するので、定数化しておいたほうが良さそうです。 | + | ActivityからFragmentDialog#show()で表示できます。第2引数にタグを設定することも出来ます。\\ |
| + | タグやリクエストコードは定数化しておいたほうが良さそう。 | ||
| FragmentManager manager = getFragmentManager(); | FragmentManager manager = getFragmentManager(); | ||
| ライン 78: | ライン 79: | ||
| public void fncCallback(String cb){ | public void fncCallback(String cb){ | ||
| - | Intent result = new Intent(); | + | Intent result = new Intent(); |
| - | result.putExtra("callback", cb); | + | result.putExtra("callback", cb); |
| | | ||
| - | PendingIntent pi = getActivity().createPendingResult(getTargetRequestCode(), result, | + | PendingIntent pi = getActivity().createPendingResult(getTargetRequestCode(), result, |
| - | PendingIntent.FLAG_ONE_SHOT); | + | PendingIntent.FLAG_ONE_SHOT); |
| - | try { | + | try { |
| - | pi.send(getActivity().RESULT_OK); | + | pi.send(getActivity().RESULT_OK); |
| - | } catch (PendingIntent.CanceledException e) { | + | } catch (PendingIntent.CanceledException e) { |
| - | e.printStackTrace(); | + | e.printStackTrace(); |
| } | } | ||
| } | } | ||
| * Activity側の実装 | * Activity側の実装 | ||