() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LearningViewHolder {
val view = RecyclerviewlearningBinding.inflate(LayoutInflater.from(context))
return LearningViewHolder(view)
}
override fun getItemCount(): Int {
return learningarraylist.size
}
override fun onBindViewHolder(holder: LearningViewHolder, position: Int) {
holder.binding.apply {
textviewrecycleritemlearning.text=learningarraylist.get(position).name
imageviewlearningitem.setImageResource(learningarraylist.get(position).images)
linearlayoutitemlearning.setOnClickListener {
val intent =Intent(context, MainActivity5Learing::class.java)
intent.putExtra("titlename",textviewrecycleritemlearning.text.toString())
context.startActivity(intent)
}
}
}
class LearningViewHolder(var binding: RecyclerviewlearningBinding):ViewHolder(binding.root)
}
package com.example.enlishforkidsbeginner.adapters
import android.annotation.SuppressLint
import android.content.Context
import android.media.MediaPlayer
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.example.enlishforkidsbeginner.databinding.LearningrecyclerviewItemBinding
import com.example.enlishforkidsbeginner.model.LearningModel
class LearningAlphabetAdapter constructor(
val context: Context,
val arrayList: ArrayList
):RecyclerView.Adapter(){
@SuppressLint("SuspiciousIndentation")
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LearningAlphabetViewHolder {
val view = LearningrecyclerviewItemBinding.inflate(LayoutInflater.from(context))
return LearningAlphabetViewHolder(view)
}
override fun getItemCount(): Int {
return arrayList.size
}
override fun onBindViewHolder(holder: LearningAlphabetViewHolder, position: Int) {
holder.binding.apply {
textviewletter.text= arrayList.get(position).text
imageviewletter.setImageResource(arrayList.get(position).image)
linearlayoutmedia.setOnClickListener {
val mediaPlayer=MediaPlayer.create(context,arrayList.get(position).music)
mediaPlayer.start()