正如标题所示.
我Fragment从这里下载了代码,http://developer.android.com/shareables/training/FragmentBasics.zip.
这是来自Android官方开发者网站的片段示例.http://developer.android.com/training/basics/fragments/fragment-ui.html
这是MainActivity.java's onCreate():
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news_articles);
// Check whether the activity is using the layout version with
// the fragment_container FrameLayout. If so, we must add the first fragment
if (findViewById(R.id.fragment_container) != null) {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should …Run Code Online (Sandbox Code Playgroud)