Fran Fran - 1 year ago 82
Android Question

Is index important in addView()?

I can't understand the function of

addView(View child, int index)
of a
What's the
for? Can be
negative value? Does it affect to the
or the way to display the
I have tested the code with and without
and I can't see the difference.

Answer Source

The point of the index attribute is to allow you change the order of views.

Let's say you have a massive list of views, and want to suddenly put one at the very top. If you specify that view's index as 0, it will be the first to display in the layout.

The Android documentation talks briefly about this.

A previous SO question shows the practical use for this: Android: How to add view at start of layout?.

Unless you really need to specify a position for the view, just use addView(view).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download