Androidで双方向データバインディングを使用しようとしていますが、次のようなエラーが発生します。あなたが見るこのタイトル。com.example.widget.MyTableRowの値型java.lang.Stringで属性 'app:rowContentText'のゲッターが見つかりません
MyTableRowは、カスタムの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();
}
}
は、その後、私はXMLファイルでそれを使用します。
<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}"/>
モデルファイルは次のとおりです。
public class TableModel {
public String shopName = "lalala";
....
}
それがあるときスニペットの作品一方向のデータバインディング(@ {shopInfo.shopName})、双方向ビンの場合は失敗(属性のゲッターが見つかりません)鼎。
また、この問題についてquestionが見つかりましたが、答えがうまくいきませんでした。
//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 {
...
}
これはIDEかdataBinding libのバグですか?
のようなものでなければなりませんが、ゲッターを持つクラスはMyShopTableRow''です。レイアウトファイルでMyShopTableRowを使用していることを確認してください。 –
@GeorgeMount、あいまいな記述と間違ったコードを残念に思っています(それは、いくつかの重要な情報を隠しているからですが、変更は絶対に正しくありません)。 – 2BAB