diff --git a/UMC_6th/app/src/main/java/com/example/umc_6th/AlbumRVAdapter.kt b/UMC_6th/app/src/main/java/com/example/umc_6th/AlbumRVAdapter.kt index 7116d92..be6a52f 100644 --- a/UMC_6th/app/src/main/java/com/example/umc_6th/AlbumRVAdapter.kt +++ b/UMC_6th/app/src/main/java/com/example/umc_6th/AlbumRVAdapter.kt @@ -7,6 +7,15 @@ import com.example.umc_6th.databinding.ItemAlbumBinding class AlbumRVAdapter(private val albumlist:ArrayList) : RecyclerView.Adapter() { + 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) @@ -15,6 +24,9 @@ class AlbumRVAdapter(private val albumlist:ArrayList) : 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 diff --git a/UMC_6th/app/src/main/java/com/example/umc_6th/HomeFragment.kt b/UMC_6th/app/src/main/java/com/example/umc_6th/HomeFragment.kt index 93a7adf..56fe9fd 100644 --- a/UMC_6th/app/src/main/java/com/example/umc_6th/HomeFragment.kt +++ b/UMC_6th/app/src/main/java/com/example/umc_6th/HomeFragment.kt @@ -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))