码迷,mamicode.com
首页 > 移动开发 > 详细

Android初学第84天

时间:2018-06-22 19:32:22      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:rac   TE   java   import   source   get   set   and   tac   

Android初学第84天

24_NerdLauncher

代码

Nerdlauncher

NerdLauncherActivity.java

package com.bignerdranch.android.nerdlauncher;

import android.support.v4.app.Fragment;

public class NerdLauncherActivity extends SingleFragmentActivity {

    @Override
    protected Fragment createFragment() {
        return NerdLauncherFragment.newInstance();
    }
}

SingleFragmentActivity.java

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();
        }
    }
}

Android初学第84天

标签:rac   TE   java   import   source   get   set   and   tac   

原文地址:https://www.cnblogs.com/zhouheng0918/p/9215165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!