Created
August 25, 2017 10:21
-
-
Save AkshatAgrawal05/2ea639fb65c586748b7f85ce5bf75b2c to your computer and use it in GitHub Desktop.
Recycler View Adapter in Kotlin
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 RedditAdapter(mainActivity: Context, mList: MutableList<Child>) : Adapter<RedditAdapter.ViewHolder>() { | |
var mContext = mainActivity | |
var mList = mList | |
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { | |
return ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.reddit_item_view, parent, false)) | |
} | |
override fun getItemCount(): Int { | |
return mList!!.size | |
} | |
override fun onBindViewHolder(holder: ViewHolder?, position: Int) { | |
var reddit: Child = mList?.get(position)!! | |
holder?.bindItems(reddit.data.title)!! | |
} | |
class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView) { | |
fun bindItems(title: String) { | |
itemView.tv_item_name.text = title | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment