Last Updated: February 25, 2016
·
464
· sambarboza

Setting/Getting IDs on custom Views on Android

public class CustomView extends ViewGroup {

private View childView;

public LookView(Context context, AttributeSet attrs) {
    super(context, attrs);
    //Never do it here
    //this.childView = this.findViewById(R.id.childView);
}

@Override
protected void onFinishInflate() {
    //Do it here :)
    this.childView = this.findViewById(R.id.childView);
}

}