今天初步学习到了Fragment ,如果说activity是一堵墙, 那么它类似于一个便利贴,能将内容写在上面粘贴到任意一面墙上, 而不需要每一堵墙上都写满相同的内容 ,
下面我们来了解 怎样编写 Fragment 以及 动静态加载 传参 的代码
Fragment 之 静态传参
第一步:创建一个 FragmentA.java 文件, 编写如下代码
packagecom.lym.week12.fragment;importandroid.os.Bundle;importandroid.support.annotation.Nullable;importandroid.support.v4.app.Fragment;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.ViewGroup;importcom.lym.week12.R;public class FragmentA extendsFragment{//初始化布局和控件
@Nullable
@OverridepublicView onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {/*** LayoutInflater 布局加载器*/View view= inflater.inflate(R.layout.fragment_a,null);
View textView=view.findViewById(R.id.text_view);returnview;
}
}
第二步:在layout下编写上诉代码中需要用到的 fragment.fragm