如何在不使用意图的情况下将值从适配器传递到活动? kotlin android androidx

问题描述 投票:0回答:1

This is main activity that the adapter is for

This is second activity where intent in main activity is directed to

This is third activity where I am trying to get restaurant object selected in main activity to go to so that i can add to one of its fields

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    val restaurant = restaurants[position]
    holder.bind(restaurant)

    holder.itemView.setOnClickListener{
         model = restaurants.get(position)

试图将模型^^^从适配器传递到活动,以在活动中编辑模型对象。我已经在此适配器中使用了一种意图,它可以启动不同的活动。我只想将模型发送到其他第三项活动。

android kotlin androidx
1个回答
1
投票
适配器具有其模型(在您的情况下为餐厅),并且是活动/片段,已将其传递给构造函数中的适配器。适配器应该是更新其自身模型的适配器。
© www.soinside.com 2019 - 2024. All rights reserved.