android中的inflater.inflate()里边的几个参数是什么意思?还有container是怎么被传入的?API看的迷迷糊糊的,还请高人指点一下啊~下面是一个创建一个Fragment的代码,函数onCreateView中的ViewGroup container是合何时被传入的?还有就是View rootView=inflater.inflate(R.layout.fragment_main,container,false);中container和false这两个参数是分别是什么意思呢?public class MainActivityFragment extends Fragment { public static final String ITEM_ID="item_id"; BookContent.Book book; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments().containsKey(ITEM_ID)){//activity启动的时候会给Fragment一个信号 book=BookContent.ITEM_MAP.get(getArguments().getInt(ITEM_ID)); } } public MainActivityFragment() { } //该方法将返回的View作为Fragment显示组件 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView=inflater.inflate(R.layout.fragment_main,container,false); if (book!=null){ ((TextView)rootView.findViewById(R.id.book_title)).setText(book.title); ((TextView)rootView.findViewById(R.id.book_desc)).setText(book.desc); } return rootView; }}
- 2 回答
- 0 关注
- 5856 浏览
添加回答
举报
0/150
提交
取消