Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notifyItemChanged 刷新之后其他item会暂停 #209

Open
ThinkAgains opened this issue Nov 20, 2023 · 0 comments
Open

notifyItemChanged 刷新之后其他item会暂停 #209

ThinkAgains opened this issue Nov 20, 2023 · 0 comments

Comments

@ThinkAgains
Copy link

ThinkAgains commented Nov 20, 2023

所有设备均可复现

MainActivity 集合数据放不同的 png url

package com.test.myapplication
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val recyclerView = findViewById(R.id.recyclerView)
val imageAdapter = ImageAdapter(
mutableListOf(
ImageBean("73746.png"),
ImageBean("11420.png"),
ImageBean("55232.png"),
ImageBean("27916.png"),
ImageBean("89571.png"),
ImageBean("97790.png"),
ImageBean("64916.png")
)
)
recyclerView.apply {
layoutManager = LinearLayoutManager(context)
adapter = imageAdapter
imageAdapter.setOnItemClickListener { _, _, position ->
imageAdapter.data[position].check = !imageAdapter.data[position].check
imageAdapter.notifyItemChanged(position)
}
}
}
}

适配器

`
package com.test.myapplication

import androidx.appcompat.widget.AppCompatImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class ImageAdapter(data: MutableList?) :
BaseQuickAdapter<ImageBean, BaseViewHolder>(R.layout.item_image_layout, data) {

override fun convert(holder: BaseViewHolder, item: ImageBean) {
    val ivImage = holder.getView<AppCompatImageView>(R.id.ivImage)
    Glide.with(ivImage.context).load(item.url).into(ivImage)
    if (item.check) {
        holder.setText(R.id.tvText, "选我了")
    } else {
        holder.setText(R.id.tvText, "sssssssss")
    }
}

}
`

glide配置
`
package com.test.myapplication

import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.module.AppGlideModule

@GlideModule
class SelfGlideModule : AppGlideModule()
`

bean
`
package com.test.myapplication

data class ImageBean(
var url: String = "",
var check: Boolean = false
)
item_image_layout布局

<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">

<androidx.appcompat.widget.AppCompatImageView
    android:id="@+id/ivImage"
    android:layout_width="60dp"
    android:layout_height="60dp" />

<androidx.appcompat.widget.AppCompatTextView
    android:id="@+id/tvText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</androidx.appcompat.widget.LinearLayoutCompat>
`

activity_main布局
`

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
`

build.gradle
`
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

implementation 'androidx.core:core-ktx:1.1.0'

implementation 'androidx.appcompat:appcompat:1.1.0'

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

implementation 'com.google.android.material:material:1.4.0'

testImplementation 'junit:junit:4.12'

androidTestImplementation 'androidx.test.ext:junit:1.1.1'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
api 'com.github.bumptech.glide:glide:4.13.2'

api 'com.github.bumptech.glide:annotations:4.13.2'

kapt 'com.github.bumptech.glide:compiler:4.13.2'

api 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.7'
api "androidx.recyclerview:recyclerview:1.2.0"

api 'com.github.penfeizhou.android.animation:apng:2.23.0'

api 'com.github.penfeizhou.android.animation:glide-plugin:2.23.0'

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant