diff --git a/app/src/main/java/jackall/devrealm/adapter/MainAdapter.kt b/app/src/main/java/jackall/devrealm/adapter/MainAdapter.kt new file mode 100644 index 0000000..56859a9 --- /dev/null +++ b/app/src/main/java/jackall/devrealm/adapter/MainAdapter.kt @@ -0,0 +1,40 @@ +package jackall.devrealm.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.devrealm.R +import jackall.devrealm.databinding.ListItemBinding +import jackall.devrealm.viewmodel.ItemViewModel + +/** + * Created by matsumoto_k on 2017/11/08. + */ +class MainAdapter(val context: Context, val items: ArrayList) : RecyclerView.Adapter() { + override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder { + val binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.list_item, parent, false) + return ViewHolder(binding) + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { + + } + + override fun getItemCount(): Int { + return items.count() + } + + fun insert(item: ItemViewModel) { + items.add(item) + notifyItemInserted(itemCount) + } + + fun remove(position: Int) { + items.removeAt(position) + notifyItemRemoved(position) + } + + inner class ViewHolder(val binding: ListItemBinding) : RecyclerView.ViewHolder(binding.root) +} \ No newline at end of file