2

may i know the meaning of

 public View getView(int position, View view, ViewGroup parent){
            if (view ==null)
                view = getLayoutInflater().inflate(R.layout.listview_item, parent, false);
        }
  • why it contain 3 parameter, wht is the meaning of those three param
  • layout inflater it must work with view? why?

anyone can explain to me thank!

Mickey
  • 149
  • 1
  • 11
  • Did you already read the [documentation](http://developer.android.com/reference/android/view/LayoutInflater.html) and if so, what is unclear there? – laalto Jun 07 '14 at 16:45
  • Please add more information to your question so others can assist you. – simonmorley Jun 07 '14 at 17:01
  • http://stackoverflow.com/questions/5026926/making-sense-of-layoutinflater can refer to here – Mickey Jun 08 '14 at 16:15

3 Answers3

7

LayoutInflater has two relevant overloads of inflate:

public View inflate (int resource, ViewGroup root, boolean attachToRoot)
public View inflate (int resource, ViewGroup root)

The second parameter is the view you want to refer as the root of the view you're inflating. If attachToRoot is true, it will become the inflated view's parent view. If not, it'll just help create the correct layout.

If you use the second overload, attachToRoot is assumed to be true and if you supply the (optional) root, it'll be automatically attached as a parent view to the inflated view.

Eran Goldin
  • 980
  • 12
  • 21
2

What's wrong with the documentation? http://developer.android.com/reference/android/view/LayoutInflater.html#inflate(int, android.view.ViewGroup, boolean)

nyarlathotep77
  • 181
  • 1
  • 9
2

The official definition of the method inflate comes in this way:

inflate(int resource, ViewGroup root, boolean attachToRoot)

Quoting we obtain the following concepts:

resource: ID for an XML layout resource to load (e.g., R.layout.main_page)

root: Optional view to be the parent of the generated hierarchy (if attachToRoot is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToRoot is false.)

attachToRoot: Whether the inflated hierarchy should be attached to the root parameter? If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML.

For more information http://developer.android.com/reference/android/view/LayoutInflater.html#inflate(int, android.view.ViewGroup, boolean)

lmove
  • 317
  • 3
  • 11
  • FWIW, `R.layout.listview_item` is not an `XmlPullParser`. There's another overload that takes an int as the first arg. – laalto Jun 07 '14 at 16:52