How to get child views of a ViewGroup in Android?

10,501

Solution 1

WebView has methods getChildCount() and getChildAt(int index). You can try to use these methods, but better solution is Bixi's one.

Solution 2

Why don't you use findViewById ?

TextView subElement = (TextView) webview.findViewById(R.id.subelement);
subElement.setText("Oh Hi");

If you really want to iterate over the child, you can also use ViewGroup::getChildAt() and ViewGroup::getChildCount()

Share:
10,501
Hossein POURAKBAR
Author by

Hossein POURAKBAR

Updated on June 04, 2022

Comments

  • Hossein POURAKBAR
    Hossein POURAKBAR almost 2 years

    I have to get child views of WebView. For some text manipulations, I wonder if there is a way to set attributes of child views, for example:

    View[] childs = webView.getChilds;
    View ch = childs[0];
    ch.setText("manipulated text");
    
  • Hossein POURAKBAR
    Hossein POURAKBAR over 11 years
    I don't know about inner views, can you write some applied code? Thanks.
  • Jscti
    Jscti over 11 years
    All you need is in my post, if you need code example : I strongly suggest you to read the Android Training pages : developer.android.com/training/index.html because it's some very basic android methods
  • BORSHEVIK
    BORSHEVIK about 8 years
    findViewById() Is exacting to resources