Android初学第26天

盛年不重来,一日难再晨,及时当勉励,岁月不待人。这篇文章主要讲述Android初学第26天相关的知识,希望能为你提供帮助。
android初学第26天【Android初学第26天】10_FragmentArguments
代码 SingleFragmentActivity.java

package com.bignerdranch.android.criminalintent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; public abstract class SingleFragmentActivity extends AppCompatActivity {protected abstract Fragment createFragment(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fragment); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment == null) { fragment = createFragment(); fm.beginTransaction() .add(R.id.fragment_container, fragment) .commit(); } } }


    推荐阅读