Programmatically add a view to the middle of LinearLayout

I have a LinearLayout with two views

<LinearLayout>
    <TextView />
    <Textview />
</LinearLayout>

Through my program, I want to add a third TextViewbetween these two existing ones TextViews. ” This was easy to do with parameter RelativeLayoutwith parameter layout_below. How to do it for LinearLayout?

+5
source share
1 answer

LinearLayout.addView(View v, int index)

Documents are a good place to start with these kinds of things.

Just pass the pointer where you want to place it (i.e. the second position will be index 1).

+18
source

All Articles