Last active
August 29, 2015 14:18
-
-
Save nein37/3d7acf2780b588b9f644 to your computer and use it in GitHub Desktop.
NestedFragment.java
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
public class NestedFragment extends Fragment { | |
static final int REQUEST_ACTIVITY = 100; | |
static final int REQUEST_FRAGMENT = 200; | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.fragment_nested, null); | |
((Button) view.findViewById(R.id.button1)).setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
// Activity呼び出し | |
Intent intent = new Intent(getActivity(), ChildActivity.class); | |
startActivityForResult(intent, REQUEST_ACTIVITY); | |
} | |
}); | |
((Button) view.findViewById(R.id.button2)).setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
// Fragment呼び出し | |
DialogFragment dialogFragment = new MyDialogFragment(); | |
dialogFragment.setTargetFragment(NestedFragment.this,REQUEST_FRAGMENT); | |
dialogFragment.show(getFragmentManager(),"dialog"); | |
} | |
}); | |
return view; | |
} | |
@Override | |
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
switch (requestCode){ | |
case REQUEST_ACTIVITY: | |
// Activityからの戻り | |
// 実際にはネストされたFragmentでは呼び出されない | |
break; | |
case REQUEST_FRAGMENT: | |
// Fragmentからの戻り | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment