如何处理适配器中editText和image视图上的事件

时间:2019-05-23 12:38:45

标签: kotlin android-recyclerview adapter

我正在recyclerView中设置来自Firestore的列表,并使用适配器来处理该项目。我的目标是更新列表信息。 当用户单击listView中的名称时,它将在Firestore列表中更新与图像视图相同的名称。我找不到解决方案。有什么想法吗?

class AnimalAdapter(val Animal: List<String>, val listener: (Int) -> Unit): RecyclerView.Adapter<AnimalAdapter.ViewHolder>() {

    class ViewHolder(itemView: View):RecyclerView.ViewHolder(itemView) {

        val name = itemView.findViewById<EditText>(R.id.text_card_name)
        val edit = itemView.findViewById<ImageView>(R.id.edit)
        val image = itemView.findViewById<ImageView>(R.id.image_card_cover)
        val map = itemView.findViewById<ImageView>(R.id.map)
        val history = itemView.findViewById<ImageView>(R.id.history)

        init {
            itemView.map.setOnClickListener {
                val intent = Intent(itemView.context, MapsActivity::class.java)
                itemView.context.startActivity(intent)
           }

            itemView.history.setOnClickListener {
               // val activity = it.getContext() as AppCompatActivity
               // val myFragment = Historique()
               // activity.supportFragmentManager.beginTransaction().replace(R.id.cardList, myFragment)
               // .addToBackStack(null).commit()}
            }

            itemView.edit.setOnClickListener {
                val intent = Intent(itemView.context, EditAnimal::class.java)
                itemView.context.startActivity(intent)
            }
        }
    }

    override fun onCreateViewHolder(p0: ViewGroup, p1: Int): AnimalAdapter.ViewHolder {

        val v = LayoutInflater.from(p0.context).inflate(R.layout.item_layout3, p0, false)

        return ViewHolder(v)
    }

    override fun getItemCount() = Animal.size

    override fun onBindViewHolder(p0: AnimalAdapter.ViewHolder, p1: Int) {

0 个答案:

没有答案