我有一个从api接收到的图像的水平列表,我想实现将其中一项保存到单独的文件夹中。如何在列表的末尾添加一个外观会有所不同的附加元素,我想将其用作用户的存储空间?
我的适配器
Сlass ImagesAdapter : RecyclerView.Adapter<ImagesAdapter.ViewHolder>() {
private var images: List<Image> = ArrayList()
fun setList(newImages: List<Image>) {
images = newImages
notifyDataSetChanged()
}
override fun getItemCount() = images.size
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(images[position])
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view: View =
LayoutInflater.from(parent.context).inflate(R.layout.item_images, parent, false)
return ViewHolder(view)
}
var onItemClickListener: (Image) -> Unit = {}
inner class ViewHolder(private val viewItem: View) : RecyclerView.ViewHolder(viewItem) {
fun bind(image: Image) {
viewItem.apply {
title.text = image.title
setOnClickListener {
onItemClickListener(image)
}
val request = ImageRequest.Builder(context)
.data(image.imageUrl)
.target(
onStart = {//todo},
onSuccess = { imageMini.setImageDrawable(it)},
).build()
context.imageLoader.enqueue(request)
}
}
}
api为我提供4张图片,我想添加5个其他项目,例如文件夹
答案 0 :(得分:0)