<variable name="hoge_text" type="String">
Than,
<variable name="hogeText" type="String">
The story that I don't think I'm in trouble. Because I was addicted to it.
"When I tried to use the variable of snake_case in the<include>
file, I couldn't access it."
child.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="value_text"
type="String" />
</data>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{value_text}"/>
</layout>
parent.xml
<Parent element omitted>
<include
layout="@layout/child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:value_text="@{someVariable}"/>
</Parent element omitted>
ChildBindingImpl.java
public void setValueText(@Nullable java.lang.String ValueText) {
this.mValueText = ValueText;
synchronized(this) {
mDirtyFlags |= 0x2L;
}
notifyPropertyChanged(BR.value_text);
super.requestRebind();
}
ParentBindingImpl.java
@Nullable
private final app.package.name.databinding.ChildBinding mboundView;
// ~~~Abbreviation~~~
this.mboundView.setValue_text(someVariableGetValue); // <-You! !!
error:Can't find symbol
this.mboundView3.setValue_text(someVariableGetValue);
^
symbol:Method setValue_text(String)
So, the function name generated by the ʻapp: snake_caseattribute is Build fails because it is different from the function name generated by
I feel like "Then ʻapp: camelCase &
As I wrote at the beginning.
child.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="valueText"
type="String" />
</data>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{valueText}"/>
</layout>
parent.xml
<Parent element omitted>
<include
layout="@layout/child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:valueText="@{someVariable}"/>
</Parent element omitted>
Let's change the definition to camelCase.
I don't think it's been stated so much, I also searched for a two-word variable name in the Official sample. It was camelCase. (ʻUserList`)
<data>
<import type="com.example.User"/>
<import type="java.util.List"/>
<variable name="user" type="User"/>
<variable name="userList" type="List<User>"/>
</data>
There is a feeling that this area (then the id of resource is also camelCase?) Is not consistent even in the code provided by Google, so it seems that it will be a small topic from old times.
Recommended Posts