I'm trying to use two-way data binding in Android, but it throws an error like this title you see.
MyTableRow is a custom viewgroup:
public class MyShopTableRow extends RelativeLayout {
...
public void setRowContentText(String text) {
mRowInputEt.setText(text);
}
public String getRowContentText() {
if(TextUtils.isEmpty(mRowInputEt.getText())){
return "";
}
return mRowInputEt.getText().toString();
}
}
Then I use it in XML file:
<data>
<variable
name="shopInfo"
type="com.example.TableModel" />
</data>
<com.example.widget.MyTableRow
android:layout_width="match_parent"
android:layout_height="46dp"
android:layout_marginTop="11dp"
...
app:rowInputType="text"
app:size="regular"
...
app:rowContentText="@={shopInfo.shopName}"/>
The Model file is :
public class TableModel {
public String shopName = "lalala";
....
}
The Snippet works when it is just a one-way data binding (@{shopInfo.shopName}), but failed (cannot find the getter for attribute) if it is two-way binding.
I also found a question about this issue, but the answer didn't work for me.
//The answer will throw an error below
//Error:(55, 17) Could not find event 'rowContentTextAttrChanged' on View type 'com.example.MyTableRow'
@InverseBindingMethods({
@InverseBindingMethod(type = MyShopTableRow.class, attribute = "rowContentText"),
})
public class MyShopTableRow extends RelativeLayout {
...
}
Is it a bug of IDE or dataBinding lib?