Created
September 13, 2017 05:58
-
-
Save farooqkhan003/d43d59ba619b2620f4886e096f8d8422 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.example.farooq.firstappwithkotlin | |
import android.support.v7.widget.RecyclerView | |
import android.util.Log | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import android.widget.ImageView | |
import android.widget.TextView | |
/** | |
* Created by farooq on 9/12/2017. | |
*/ | |
class RecyclerViewAdapter(val list:ArrayList<MyData>):RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewAdapter.ViewHolder { | |
val v = LayoutInflater.from(parent.context).inflate(R.layout.list_item, parent, false) | |
return ViewHolder(v) | |
} | |
//this method is binding the data on the list | |
override fun onBindViewHolder(holder: RecyclerViewAdapter.ViewHolder, position: Int) { | |
holder.bindItems(list[position]) | |
} | |
//this method is giving the size of the list | |
override fun getItemCount(): Int { | |
return list.size | |
} | |
class ViewHolder(view: View): RecyclerView.ViewHolder(view) { | |
fun bindItems(data : MyData){ | |
val _textView:TextView = itemView.findViewById(R.id.textview) | |
val _imageView:ImageView = itemView.findViewById(R.id.imageview) | |
_textView.text = data.text | |
_imageView.setImageBitmap(data.image) | |
//set the onclick listener for the singlt list item | |
itemView.setOnClickListener({ | |
Log.e("ItemClicked", data.text) | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment