【kotlin android中Recyclerview的适配器类】须知少年凌云志,曾许人间第一流。这篇文章主要讲述kotlin android中Recyclerview的适配器类相关的知识,希望能为你提供帮助。
This the base code for creating adapter class which is used for filling recyclerview in android.
This snippet is written in kotlin but it is same to the java version
- class ClassName(val list:ArrayList< Type of your list> ):RecyclerView.Adapter< ClassName.ViewHolder> () {
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ClassName.ViewHolder {
- val v = LayoutInflater.from(parent.context).inflate(R.layout.item_layout, parent, false)
- return ViewHolder(v)
- }
- override fun getItemCount(): Int {
- return list.size
- }
- override fun onBindViewHolder(holder: ClassName.ViewHolder, position: Int) {
- holder.bindItems(list[position])
- }
- class ViewHolder(itemview: View):RecyclerView.ViewHolder(itemview)
- {
- fun bindItems(t: type of your list){
- }
- }
- }
推荐阅读
- Android 开发环境搭建及程序打包方法
- Android OS的image文件组成
- Android-原笔迹手写的探索与开发
- 当前Android开发人员如何提升岗位竞争力
- mybatis使用Dao和Mapper方式
- [Android] Android 支持下拉刷新上拉加载更多 的 XRecyclerview
- 一种解决 MacBook 里的 App Store 无法登录的问题
- Delphi通过AppendMenu和DeleteMenu在系统菜单中添加删除菜单项
- [Functional Programming] From simple implementation to Currying to Partial Application