evant / binding-collection-adapter

Easy way to bind collections to listviews and recyclerviews with the new Android Data Binding framework
Apache License 2.0
1.92k stars 255 forks source link

Custom adapter has a generic bug #205

Open chenyannan opened 4 years ago

chenyannan commented 4 years ago

Is this a general databinding issue or question? You are more likely to get a response from somewhere like StackOverflow.

Issue

Please be as detailed as possible and include a (formatted) stacktrace if relevant. A sample project that reproduce the problem goes a long way!

Feature Request

Please give an example use-case on why the feature is useful. Keep in mind the scope of this project is to bind data to RecyclerView/ListView/ViewPager etc, not to add additional features to those views.

chenyannan commented 4 years ago

implementation 'me.tatarka.bindingcollectionadapter2:bindingcollectionadapter:4.0.0' implementation 'me.tatarka.bindingcollectionadapter2:bindingcollectionadapter-recyclerview:4.0.0' implementation 'me.tatarka.bindingcollectionadapter2:bindingcollectionadapter-viewpager2:4.0.0'

`public class MainPageViewModel extends RVPresenterViewModel<NewsInfoBean, NewsItemObservable> {

public final ObservableList<NewsItemObservable> items = new ObservableArrayList<>();
public final ItemBinding<NewsItemObservable> itemBinding = ItemBinding.of(new OnItemBind<NewsItemObservable>() {
    @Override
    public void onItemBind(@NonNull ItemBinding itemBinding, int position, NewsItemObservable item) {
        itemBinding.set(BR.item, R.layout.item_news);

    }
});`

`

    <variable
        name="mainPageVM"
        type="com.demo.mvvmapplication.ui.fragment.home.MainPageViewModel" />

    <variable
        name="adapter"
        type="me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter"/>
</data>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/fmpRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="40dp"
        android:focusable="false"
        android:overScrollMode="never"
        app:adapter="@{adapter}"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:itemBinding="@{mainPageVM.getBindingItem()}"
        app:items="@{mainPageVM.getBindingItems()}"/>`

\databinding\FragmentMainPageBindingImpl.java:125: 错误: 无法将类 BindingRecyclerViewAdapters中的方法 setAdapter应用到给定类型; me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapters.setAdapter(this.fmpRecyclerView, mainPageVMGetBindingItem, mainPageVMGetBindingItems, (me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter)null, (me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter.ItemIds)null, (me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter.ViewHolderFactory)null, (androidx.recyclerview.widget.AsyncDifferConfig)null); ^ 需要: RecyclerView,ItemBinding<? super T>,List<T>,BindingRecyclerViewAdapter<T>,ItemIds<? super T>,ViewHolderFactory,AsyncDifferConfig<T> 找到: RecyclerView,ItemBinding<CAP#1>,ObservableList<CAP#2>,BindingRecyclerViewAdapter,ItemIds,ViewHolderFactory,AsyncDifferConfig 原因: 无法推断类型变量 T (参数不匹配; ItemBinding<CAP#1>无法转换为ItemBinding<? super T>) 其中, T是类型变量: T扩展已在方法 <T>setAdapter(RecyclerView,ItemBinding<? super T>,List<T>,BindingRecyclerViewAdapter<T>,ItemIds<? super T>,ViewHolderFactory,AsyncDifferConfig<T>)中声明的Object 其中, CAP#1,CAP#2是新类型变量: CAP#1从?的捕获扩展Object CAP#2从?的捕获扩展Object

chenyannan commented 4 years ago

adapter should can add header and fooder