满堂花醉三千客,一剑霜寒十四州。这篇文章主要讲述Android初学第81天相关的知识,希望能为你提供帮助。
android初学第81天【Android初学第81天】20_MVVM
代码
BeatBox
BeatBoxActivity.java
package com.bignerdranch.android.beatbox;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class BeatBoxActivity extends SingleFragmentActivity {
@Override
protected Fragment createFragment() {
return BeatBoxFragment.newInstance();
}
}
SingleFragmentActivity.java
package com.bignerdranch.android.beatbox;
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();
protected int getLayoutResId() {
return R.layout.activity_fragment;
}@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutResId());
FragmentManager manager = getSupportFragmentManager();
Fragment fragment = manager.findFragmentById(R.id.fragment_container);
if (fragment == null) {
fragment = createFragment();
manager.beginTransaction()
.add(R.id.fragment_container, fragment)
.commit();
}
}
}
推荐阅读
- Android初学第80天
- Android初学第73天
- Android xUtils3使用 - 获取网络图片
- DAPP超详细解释
- 1. SpringBoot启动后,报异常:This application has no explicit mapping for /error, so you are seeing this as
- Ubuntu(64位)编译Android源码常见错误解决办法
- kali之Nmap (Network Mapper(网络映射器)
- android -------- 混淆打包报错(warning - InnerClass annotations are missing corresponding EnclosingMember a
- 一SpringMVC源码之DispatcherServletAbstractHanderMapping