Skip to content

Commit

Permalink
[simba/#28] feat:: recyclerView->albumFragment 클릭 이벤트 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
BAEK0111 committed May 19, 2024
1 parent ca3ed59 commit 4fa8e17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/AlbumRVAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import com.example.umc_6th.databinding.ItemAlbumBinding

class AlbumRVAdapter(private val albumlist:ArrayList<Album>) : RecyclerView.Adapter<AlbumRVAdapter.ViewHolder>() {

interface MyItemClickListener{
fun onItemClick()
}

private lateinit var mItemClickListener : MyItemClickListener
fun setMyItemClickListener(itemClickListener: MyItemClickListener){
mItemClickListener = itemClickListener
}

override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): AlbumRVAdapter.ViewHolder {
val binding: ItemAlbumBinding = ItemAlbumBinding.inflate(LayoutInflater.from(viewGroup.context),viewGroup,false)

Expand All @@ -15,6 +24,9 @@ class AlbumRVAdapter(private val albumlist:ArrayList<Album>) : RecyclerView.Adap

override fun onBindViewHolder(holder: AlbumRVAdapter.ViewHolder, position: Int) {
holder.bind(albumlist[position])
holder.itemView.setOnClickListener{
mItemClickListener.onItemClick()
}
}

override fun getItemCount(): Int = albumlist.size
Expand Down
7 changes: 7 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ class HomeFragment : Fragment() {
binding.homeTodayMusicAlbumRv.adapter = albumRVAdapter
binding.homeTodayMusicAlbumRv.layoutManager = LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false)

albumRVAdapter.setMyItemClickListener(object : AlbumRVAdapter.MyItemClickListener{
override fun onItemClick() {
(context as MainActivity).supportFragmentManager.beginTransaction()
.replace(R.id.main_frm,AlbumFragment())
.commitAllowingStateLoss()
}
})

val bannerAdapter = BannerVPAdapter(this)
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp))
Expand Down

0 comments on commit 4fa8e17

Please # to comment.