public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
switchFragment(new HeadlinesFragment());
}
private void switchFragment(Fragment f) {
FragmentManager fragmentM = getSupportFragmentManager();//管理对象
FragmentTransaction trans = fragmentM.beginTransaction();//切换碎片
trans.replace(R.id.activity_main, f);
trans.commit();
}
}