Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically add a view to middle of LinearLayout

I have a LinearLayout with two views

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

Through my program, I want to add a third TextView between these two existing TextViews'. It was easy to do with a RelativeLayout with layout_below parameter. How do I do this for LinearLayout?

like image 840
deeJ Avatar asked Jul 11 '12 18:07

deeJ


1 Answers

LinearLayout.addView(View v, int index)

The docs are a good place to start with this sort of thing.

Just pass an index to where you want it placed (i.e. 2nd position would be index 1).

like image 182
Kevin Coppock Avatar answered Oct 05 '22 13:10

Kevin Coppock