阶段一冲刺九
昨天任务
开始学习底部导航栏的制作
学习了fragment控件的基本用法
今天任务
学习fragment两种创建的生命周期
学习对fragment进行增删改查的增用法
package com.example.belowmeue;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.os.Bundle;
import com.example.belowmeue.fragment.DongtaiFragment;
public class DFragmentActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dfragment);
//防止fragmentManager被重复创建
if(savedInstanceState == null){
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fcv, DongtaiFragment.class,null)
.setReorderingAllowed(true) //允许自动排序
.addToBackStack(null) //创建之后添加到栈里
.commit()
;
}
}
}