https://blog.csdn.net/tu_bingbing/article/details/24143249
public class FramentTest2Activity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout. activity_main); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id. container, TestFragment.newInstance("param")).commit(); } } public static class TestFragment extends Fragment { private static final String ARG = "arg"; public TestFragment() { Log. i("INFO", "TestFragment non-parameter constructor" ); } public static Fragment newInstance(String arg){ TestFragment fragment = new TestFragment(); Bundle bundle = new Bundle(); bundle.putString( ARG, arg); fragment.setArguments(bundle); return fragment; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout. fragment_main, container, false); TextView tv = (TextView) rootView.findViewById(R.id. tv); tv.setText(getArguments().getString( ARG)); return rootView; } } }