ChildAdapter.kt 1.78 KB
package com.example.vip

import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.item_child.view.*
import kotlinx.android.synthetic.main.item_policyfield.view.*

class ChildAdapter(private val items: ArrayList<ChildItem>) :
    RecyclerView.Adapter<ChildAdapter.ViewHolder>() {

    override fun getItemCount() = items.size

    override fun onBindViewHolder(holder: ChildAdapter.ViewHolder, position: Int) {
        val item = items[position]

        holder.apply {
            bind(item)
            itemView.tag = item
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):
            ChildAdapter.ViewHolder {
        val inflatedView = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_child, parent, false)
        return ChildAdapter.ViewHolder(inflatedView)
    }

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

        private var view: View = v

        fun bind(item: ChildItem) {
            view.circleformButton.text=item.numOfChild.toString()
            view.childTextView.text=" 자녀  "+item.numOfChild.toString()

            view.womanButton.setOnClickListener {
                if(view.manButton.isChecked){
                    view.manButton.isChecked=false
                }else{
                }
            }
            view.manButton.setOnClickListener {
                if(view.womanButton.isChecked){
                    view.womanButton.isChecked=false
                }else{
                }
            }

        }
    }
}