Newer
Older
MonCalc / app / src / main / kotlin / jackall / moncalc / adapter / AnalyzeFruitAdapter.kt
package jackall.moncalc.adapter

import android.content.Context
import android.databinding.DataBindingUtil
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import jackall.moncalc.R
import jackall.moncalc.databinding.AnalyzeFruitListBinding
import jackall.moncalc.viewmodel.FruitAnalyzeItemViewModel

/**
 * Created by matsumoto_k on 2017/11/05.
 */
class AnalyzeFruitAdapter(val context: Context, val items: ArrayList<FruitAnalyzeItemViewModel>) : RecyclerView.Adapter<AnalyzeFruitAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
        val binding = DataBindingUtil.inflate<AnalyzeFruitListBinding>(LayoutInflater.from(context), R.layout.analyze_fruit_list, parent, false)
        return ViewHolder(binding)
    }

    override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
        holder?.binding?.viewModel = items.get(position)
    }

    override fun getItemCount(): Int {
        return items.count()
    }

    inner class ViewHolder(val binding: AnalyzeFruitListBinding) : RecyclerView.ViewHolder(binding.root)
}