如何初始化容器(ViewGroup中)? [英] How to initialize Container(ViewGroup)?

查看:482
本文介绍了如何初始化容器(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆