1

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

4

1 回答 1

0

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);
于 2013-08-03T23:09:10.167 回答