【问题标题】:RecyclerView adapterPosition is deprecated and Gradle throwing error as Could not find accessor bindingAdapterPositionRecyclerView adapterPosition 已弃用,Gradle 抛出错误为找不到访问器 bindingAdapterPosition
【发布时间】:2021-05-24 11:56:58
【问题描述】:

在最新的 Gradle 插件中,当我尝试访问适配器位置字段时,IDE 显示为已弃用。建议使用 getBindingAdapterPosition() 而不是 adapterPosition

但是当我尝试访问字段 getBindingAdapterPosition() 时,IDE 会抛出错误

Could not find accessor com.rizek.android.users.adapters.recyclerview.cart.ProductListAdapter.ExpandViewHolder.bindingAdapterPosition

我的 XML 文件:

        <ImageView
        android:id="@+id/imageView14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:onClick="@{()->frequencyOptionInteractor.onRecurringOptionChanged(recurringViewHolder.adapterPosition,frequencyOption)}"
        android:padding="8dp"
        app:layout_constraintBottom_toBottomOf="@+id/linearLayout12"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/linearLayout12"
        app:srcCompat="@drawable/frequency_option_selector"
        bind:stateActivated="@{frequencyOptionAdapter.selectedPosition==recurringViewHolder.bindingAdapterPosition}" />

【问题讨论】:

标签: android android-recyclerview android-databinding


【解决方案1】:

如果您使用 ViewPager2,请确保将其添加为依赖项。

implementation "androidx.viewpager2:viewpager2:1.0.0"

【讨论】:

    【解决方案2】:

    如果你还没有这样做,你可以尝试手动添加 RecyclerView 到你的

    build.gradle 
    

    文件(模块):

    // RecyclerView
    implementation "androidx.recyclerview:recyclerview:1.2.0"
    

    这对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-26
      • 2018-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-28
      相关资源
      最近更新 更多