android - 如何在 RecyclerView 中更新多个文档
问题描述
我正在尝试更新从 fileManager 中选择的文档,我已将列表中的所有文档显示为recycler view
.
override fun onBindViewHolder(holder: IndianPatientFormSixViewHolder, position: Int) {
val docs = viewModel?.patientDocumentList?.get(position)
if(viewModel?.positionOfDocumentSubmittedList?.isNotEmpty() == true){
val submittedDocPosition = viewModel?.positionOfDocumentSubmittedList?.get(position)
if(submittedDocPosition == position){
holder.docUploadedText.visibility = View.VISIBLE
} else {
holder.docUploadedText.visibility = View.GONE
}
} else {
holder.docUploadedText.visibility = View.GONE
}
holder.certificateNameTextView.text = docs?.label
holder.uploadImage.setOnClickListener {
indianPatientFormSixCallback?.onUploadButtonClicked(position,itemId = docs?.doc_id ?: 0)
}
}
以上是我的代码
我有两个列表patientDocumentList,它们来自具有文档列表的 API,并且我已经为选定的文档位置定义了positionOfDocumentSubmittedList。
如果我在更新回收站视图的位置时单击文档列表的第二位置,则会出现以下错误:
java.lang.IndexOutOfBoundsException: Index: 3, Size: 1
at java.util.ArrayList.get(ArrayList.java:437)
at com.pravin_agarwal_foundation.tpaf.ui.funding_request_patient.indian.indian_patient_form_six.IndianPatientFormSixAdapter.onBindViewHolder(IndianPatientFormSixAdapter.kt:42)
at com.pravin_agarwal_foundation.tpaf.ui.funding_request_patient.indian.indian_patient_form_six.IndianPatientFormSixAdapter.onBindViewHolder(IndianPatientFormSixAdapter.kt:14)
at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3875)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3639)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4194)
at android.view.View.layout(View.java:20703)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1915)
at android.view.View.layout(View.java:20703)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1915)
at android.view.View.layout(View.java:20703)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20703)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1915)
我还附上了更新的回收站视图的屏幕截图。
解决方案
val listSize = viewModel?.positionOfDocumentSubmittedList
if(viewModel?.positionOfDocumentSubmittedList?.isNotEmpty() == true){
for (i in 0 until listSize!!.size) {
val submittedDocPosition = viewModel?.positionOfDocumentSubmittedList?.get(position)
if (submittedDocPosition == position) {
holder.docUploadedText.visibility = View.VISIBLE
} else {
holder.docUploadedText.visibility = View.GONE
}
}
} else {
holder.docUploadedText.visibility = View.GONE
}
我已经为 SubmittedDocumentList 和 Solved 使用了循环
推荐阅读
- python - 使用其父类的实例创建对象
- ios - didFinishLaunchingWithOptions 黑屏目标 c
- matrix - Julia中具有多项式条目的矩阵
- typescript - Discord.js 指南:“客户端”类型上不存在属性“命令”
' 在打字稿中 - pyspark - pyspark 数据框搜索和替换多个值
- java - struts2中如何使用AJAX上传文件
- c# - C#:打印多个输入结果
- flutter - 无法从 Flutter 集成测试响应中找出问题所在
- python - tkinter 条目允许空白提交并且必须手动擦除
- reactjs - TypeError: email.indexOf 不是 React 中使用 react-mailchimp-subscribe 的函数