一身转战三千里,一剑曾当百万师。这篇文章主要讲述Android初学第84天相关的知识,希望能为你提供帮助。
android初学第84天【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初学第83天
- Android初学第79天
- Android初学第82天
- Android初学第80天
- Android初学第81天
- Android初学第73天
- Android xUtils3使用 - 获取网络图片
- DAPP超详细解释
- 1. SpringBoot启动后,报异常:This application has no explicit mapping for /error, so you are seeing this as