标签:rac TE java import source get set and tac
24_NerdLauncher
package com.bignerdranch.android.nerdlauncher;
import android.support.v4.app.Fragment;
public class NerdLauncherActivity extends SingleFragmentActivity {
@Override
protected Fragment createFragment() {
return NerdLauncherFragment.newInstance();
}
}
package com.bignerdranch.android.nerdlauncher;
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();
}
}
}
标签:rac TE java import source get set and tac
原文地址:https://www.cnblogs.com/zhouheng0918/p/9215165.html