如何初始化容器(ViewGroup中)? [英] How to initialize Container(ViewGroup)?
问题描述
自动在OnCreateView,有:
Automatically, in OnCreateView, there's:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
我想我的变量初始化为像OnCreateView中的AsyncTask相同的方式。
我能够初始化这些变量:
I want to initialize my variable as in the same way like OnCreateView in AsyncTask. I was able to initialize these variable :
LayoutInflater inflater;
ViewGroup container;
inflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootView = inflater.inflate(R.layout.fragment_pager_list,
container, false);
不过,我得到该容器未初始化错误!所以,我怎么能初始化呢?谢谢
However, i get the error that container isn't initialized! so how can i initialize it? Thanks
推荐答案
它的抱怨,因为你还没有的初始化的变量的值容器
- 你只有的声明的它。初始化意味着你为它分配一个值,如的ViewGroup容器= NULL;
It's complaining because you have not initialized the value of the variable container
- you have only declared it. Initialization means you assign it a value, such as ViewGroup container = null;
.
你的目的,你可以省略完全和简单地传递null来调用膨胀
。
For your purposes, you can omit that entirely and simply pass null to the call to inflate
.
LayoutInflater inflater = (LayoutInflater) ctx.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootView = inflater.inflate(R.layout.fragment_pager_list, null);
这篇关于如何初始化容器(ViewGroup中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!