2

I have this xml file:

<my.CustomView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ff0000"/>
</my.CustomView>

And this corresponding class:

public class CustomView extends LinearLayout {

    private View mSubview;

    public CustomView(Context context, AttributeSet attrs) {
        super(context, attrs);

        mSubview = getChildAt(0);
    }
}

In the constructor the first child should be assigned to mSubview. However it's null. It works when I access the first child later, for instance, when I click a button. At which point can I access my custom view's subviews?

Kuno
  • 3,492
  • 2
  • 28
  • 44

1 Answers1

1

I should read the docs more carefully...

View.onFinishInflate()

is what I was looking for.

Kuno
  • 3,492
  • 2
  • 28
  • 44