Code:
public class CustomLayoutWithText extends LinearLayout {
private Context context;
private AttributeSet attrs;
public CustomLayoutWithText(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
this.attrs = attrs;
fooAttrs();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
fooAttrs();
}
private void fooAttrs() {
int[] set = {
android.R.attr.text // idx 0
};
TypedArray a = context.obtainStyledAttributes(attrs, set);
Log.d(null, a.getString(0));
}
}
and XML:
<com.korovyansk.android.views.CustomLayoutWithText
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some text"/>
Reasonable to expect that output will be:
Some text
Some text
But it's:
Some text
null
Why second time it appears null? And how to avoid it?