Sha256: aa6a65b2731cf64b3ed7a4551483a92ee7622550094e7d173884748c8737cbc4
Contents?: true
Size: 1.69 KB
Versions: 14
Compression:
Stored size: 1.69 KB
Contents
package <%= package_name %>.strada import android.annotation.SuppressLint import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.google.android.material.textview.MaterialTextView import <%= package_name %>.R class MenuComponentAdapter : RecyclerView.Adapter<MenuComponentAdapter.ViewHolder>() { private val type = R.layout.menu_component_adapter_row private var action: ((MenuComponent.Item) -> Unit)? = null private var items = emptyList<MenuComponent.Item>() @SuppressLint("NotifyDataSetChanged") set(value) { field = value notifyDataSetChanged() } fun setData(items: List<MenuComponent.Item>) { this.items = items } fun setListener(action: (item: MenuComponent.Item) -> Unit) { this.action = action } override fun onBindViewHolder(holder: ViewHolder, position: Int) { holder.bind(items[position]) } override fun getItemCount(): Int { return items.count() } override fun getItemViewType(position: Int): Int { return type } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false) return ViewHolder(view) } inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { private val textView: MaterialTextView = view.findViewById(R.id.title) fun bind(item: MenuComponent.Item) { textView.text = item.title itemView.setOnClickListener { action?.invoke(item) } } } }
Version data entries
14 entries across 7 versions & 1 rubygems