Recyclerview在两个线性布局之间的按钮单击上仅添加一个布局

时间:2020-04-14 14:34:37

标签: android kotlin android-recyclerview

回收者的物品是这样的

enter image description here

我需要的是我不知道怎么做的:当某人按下按钮时,已经存在的布局下方会出现一个与以前相同的新布局(仅适用于已单击的项目)。我已经创建了一个布局资源,该资源与需要重复的回收站视图中的linearlayout相同。

我需要多个这些,而不仅仅是一个,所以我不能只是将布局放到下面并能看到它。

这是我的适配器:

class SpentCardAdapter(var welcomeViewModel: WelcomeViewModel, var resource: Int): RecyclerView.Adapter<SpentCardAdapter.SpentCardHolder>(){

var spentCards: List<RecyclerViewSpentItems>? = null

fun setCardsList(spentCard: List<RecyclerViewSpentItems>?){
    this.spentCards = spentCard
}

override fun getItemCount(): Int {
    return spentCards?.size ?: 0
}

override fun onBindViewHolder(holder: SpentCardHolder, position: Int) {

    holder.setDataCard(welcomeViewModel, position)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SpentCardHolder {
    val layoutInflater: LayoutInflater = LayoutInflater.from(parent.context)

    val binding:ViewDataBinding = DataBindingUtil.inflate(layoutInflater, viewType, parent, false)

    return SpentCardHolder(binding)

}

override fun getItemViewType(position: Int): Int {
    return getLayoutIdForPosition(position)
}

fun getLayoutIdForPosition(position: Int): Int{
    return resource
}


class SpentCardHolder(binding: ViewDataBinding):RecyclerView.ViewHolder(binding.root){
    private var binding: ViewDataBinding? = null

    init {
        this.binding = binding


    }

    fun setDataCard(welcomeViewModel: WelcomeViewModel, position: Int){

            binding?.setVariable(BR.model, welcomeViewModel)
            binding?.setVariable(BR.position, position)
            binding?.executePendingBindings()
        }
}

}

请帮帮我,Android大师,你是我唯一的希望!

0 个答案:

没有答案