Created
June 27, 2019 05:25
-
-
Save Papashkin/153459f3b2027bfdc6475ddbff4ee3c1 to your computer and use it in GitHub Desktop.
Adapter realization with onItemClick function invokation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestAdapter( | |
private val onItemClick: (id: Int) -> Unit | |
) : ApolloBaseAdapter<DrawerItemsAdapter.TestViewHolder>() { | |
private var items: ArrayList<String> = arrayListOf() | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DrawerViewHolder { | |
val view = LayoutInflator.from(parent.context).inflate(R.layout.drawer_body_items_list, parent, false) | |
return DrawerViewHolder(view) | |
} | |
override fun getItemCount(): Int = items.size | |
fun setItems(newItems: ArrayList<DrawerItem>) { | |
items.clear() | |
items.addAll(newItems) | |
} | |
override fun onBindViewHolder(holder: VH, position: Int) { | |
holder.bind(items[position], position) | |
} | |
inner class TestViewHolder(view: View) : ApolloBaseViewHolder(view) { | |
fun bind(T: String, position: Int) { | |
with(T as DrawerItem) { | |
itemView.tvTestItem.text = this.name | |
itemView.tvTestItem.setOnClickListener { | |
onItemClick.invoke(position + 1) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment