ここに私のBindingAdapterがあります
@InverseBindingMethods({
@InverseBindingMethod(type = RecyclerView.class, attribute = "lastAdapter", method = "getLastAdapter"),
})
public class RecyclerViewBindingAdapter {
@BindingAdapter(value = {"lastAdapter"}, requireAll = false)
public static void setLastAdapter(RecyclerView view, LastAdapter adapter) {
view.setAdapter(adapter);
}
@InverseBindingAdapter(attribute = "lastAdapter")
public static LastAdapter getLastAdapter(RecyclerView view) {
return (LastAdapter) view.getAdapter();
}
}
私のgradleに RecyclerView 依存関係を追加しました:
compile "com.android.support:recyclerview-v7:25.3.1"
レイアウトでの使用方法は次のとおりです。
<android.support.v7.widget.RecyclerView
app:lastAdapter = "@{viewModel.adapter}"
... />
このレイアウトを拡張した後、viewModel バインディング変数を既に設定しています。しかし、コードを実行するたびに、gradle は常に次のエラーを表示します
Error:(48, 34) Cannot find the setter for attribute 'app:lastAdapter' with parameter type error.NonExistentClass on android.support.v7.widget.RecyclerView.
app:lastAdapter
この問題は、レイアウトから削除してからクリーンアップして再構築し、それらのapp:lastAdapter
属性を再度書き直してからプロジェクトを再構築することで解決できます。すべて正常に機能します。
それは便利な解決策ではありません。