代码为了复用,多写在fragment里,以备需求到处改变位置,比如首页的fragment,希望从单独入口进入。所需操作仅仅需几行代码。
<pre>
public classImageGridActivityextendsFragmentActivity {
private static finalStringTAG="ImageGridActivity";
@Override
protected voidonCreate(Bundle savedInstanceState) {
if(BuildConfig.DEBUG) {
Utils.enableStrictMode();
}
super.onCreate(savedInstanceState);
if(getSupportFragmentManager().findFragmentByTag(TAG) ==null) {
finalFragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(android.R.id.content, newImageGridFragment(),TAG);
ft.commit();
}
}
}
</pre>
网友评论