http://stackoverflow.com/questions/21578170/is-index-important-in-addview

Is index important in addView()?



Is index important in addView()?_android



up vote 0 down vote favorite



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



android view



 

add a comment

share | improve this question


edited Feb 5 at 13:13






IPL
363 5 21



Feb 5 at 13:06






Fran
49 2 8



1 Answer


active oldest votes


up vote 0 down vote accepted


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



 

share | improve this answer


Feb 5 at 13:10






Joe Boyle
284 3 12