How to initialize Container(ViewGroup)?

こ雲淡風輕ζ 提交于 2019-12-08 07:47:13

问题


Automatically, in OnCreateView, there's:

  @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

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


回答1:


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;.

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);


来源:https://stackoverflow.com/questions/18038163/how-to-initialize-containerviewgroup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!