Search code examples
androidandroid-layoutviewgroup

Get "getText()" from child of type TextView within a custom ViewGroup at runtime


How is it possible to get "getText()" from child of type TextView within a custom ViewGroup at runtime?


Solution

  • ((TextView)viewGroup.getChildAt(indexOfTextView)).getText();
    

    Where viewGroup is the ViewGroup containing the TextView and indexOfTextView is the index in that group.

    Make sure to cast the view returned from the getChildAt method to A TextView before calling getText().

    ViewGroup Docs for getChildAt() http://developer.android.com/reference/android/view/ViewGroup.html