I have a simple layout like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.empresa.prueba.MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" android:text="Button"
app:layout_anchor="@+id/include"
app:layout_anchorGravity="center_vertical|center_horizontal"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
app:srcCompat="@drawable/image2"/>
</LinearLayout>
I want to change the label of the button while it is being created (I'm using onCreateView methods in activity instead of a custom factory). The problem is that I never get the button widget control when android calls onCreateView for each view in the layout.
I have added a log to the onCreateView Activity overrides to see what views are being created this way:
@Override
public View onCreateView(View v, String s, Context c, AttributeSet as)
{
Log.i("Inflating ---> ",s);
return super.onCreateView(v,s,c,as);
}
@Override
public View onCreateView(String s , Context c, AttributeSet as)
{
Log.i("Inflating ---> ",s);
return super.onCreateView(s,c,as);
}
But the output I get is:
I/Inflating --->: LinearLayout
I/Inflating --->: LinearLayout
I/Inflating --->: ViewStub
I/Inflating --->: ViewStub
I/Inflating --->: FrameLayout
I/Inflating --->: FrameLayout
I/Inflating --->: android.support.v7.widget.FitWindowsLinearLayout
I/Inflating --->: android.support.v7.widget.FitWindowsLinearLayout
I/Inflating --->: android.support.v7.widget.ViewStubCompat
I/Inflating --->: android.support.v7.widget.ViewStubCompat
I/Inflating --->: android.support.v7.widget.ContentFrameLayout
I/Inflating --->: android.support.v7.widget.ContentFrameLayout
I/Inflating --->: LinearLayout
I/Inflating --->: LinearLayout
As you can see neither the button nor the Imageview are passed to the onCreateView methods so, it is not possible for me to modify anything on this views. It seems this methods only receive containers?
If anyone know why this happens I would be really appreciate it.
Cheers.