Search code examples
javaandroidtextviewandroid-linearlayoutandroid-relativelayout

Android add textview above other textviews


I developed an app that dynamically creates textviews, and the desired result would be:

textview1
textview2
textview3

(then when the user creates a new textview)

textview4
textview1
textview2
textview3

but as of now, textview4 goes under textview3

the textviews are under a linearlayout.

How can I achieve the desired result?

Thank you.


Solution

  • You need to use:

    addView (View child, int index)
    

    Index being the position in the view (0 if you want to have it at the top)