I would like to start a new activity from a RecyclerView with Kotlin.
I am still exploring Kotlin and currently stuck on how to open a new activity from a RecyclerView.
class HomeScreenRecyclerAdapter : RecyclerView.Adapter<HomeScreenRecyclerAdapter.ViewHolder>()
{
private val titles = arrayOf("About Me",
"About Me", "About Me", "About Me"
)
private val details = arrayOf("Item one details", "Item two details",
"Item three details", "Item four details")
private val images = intArrayOf(R.drawable.ic_launcher_background,
R.drawable.ic_launcher_background, R.drawable.ic_launcher_background,
R.drawable.ic_launcher_background)
override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): ViewHolder {
val v = LayoutInflater.from(viewGroup.context)
.inflate(R.layout.main_card_view, viewGroup, false)
return ViewHolder(v)
}
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
viewHolder.itemTitle.text = titles[position]
viewHolder.itemDetail.text = details[position]
viewHolder.itemImage.setImageResource(images[position])
}
override fun getItemCount(): Int {
return titles.size
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val intent: Intent? = null
var itemImage: ImageView
var itemTitle: TextView
var itemDetail: TextView
init {
itemImage = itemView.findViewById(R.id.main_image_view)
itemTitle = itemView.findViewById(R.id.main_title_view)
itemDetail = itemView.findViewById(R.id.main_description_view)
itemView.setOnClickListener {
}
}
}
}
I just cant figure out how to start a new activity for each item within the RecyclerView. I know I am making it more complicated than it is.