Skip to content

Commit

Permalink
[nunu/#28] 6주차 구현4
Browse files Browse the repository at this point in the history
- RecyclerView 문제점 해결
(SparseBooleanArray 사용)
  • Loading branch information
Ssamssamukja committed May 21, 2024
1 parent 2791d2e commit 3695313
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ class LockerSavedSongFragment : Fragment() {
add(Album("Lilac", "아이유 (IU)", R.drawable.img_album_exp2))
add(Album("Drama", "에스파 (aespa)", R.drawable.img_album_drama))
add(Album("Weekend", "태연 (Tae Yeon)", R.drawable.img_album_exp6))
add(Album("Love wins all", "아이유 (IU)", R.drawable.img_album_lovewinsall))
add(Album("해야 (HEYA)", "IVE", R.drawable.img_album_heya))
add(Album("Supernova", "에스파 (aespa)", R.drawable.img_album_supernova))
add(Album("Lilac", "아이유 (IU)", R.drawable.img_album_exp2))
add(Album("Drama", "에스파 (aespa)", R.drawable.img_album_drama))
add(Album("Weekend", "태연 (Tae Yeon)", R.drawable.img_album_exp6))
add(Album("Love wins all", "아이유 (IU)", R.drawable.img_album_lovewinsall))
add(Album("해야 (HEYA)", "IVE", R.drawable.img_album_heya))
add(Album("Supernova", "에스파 (aespa)", R.drawable.img_album_supernova))
add(Album("Lilac", "아이유 (IU)", R.drawable.img_album_exp2))
add(Album("Drama", "에스파 (aespa)", R.drawable.img_album_drama))
add(Album("Weekend", "태연 (Tae Yeon)", R.drawable.img_album_exp6))
}
val lockerAlbumRecyclerAdapter = LockerAlbumRecyclerAdapter(albumDatas)
binding.rvLockerSavedSong.adapter = lockerAlbumRecyclerAdapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.example.umc_6th.adapter

import android.util.SparseBooleanArray
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.umc_6th.Album
import com.example.umc_6th.databinding.ItemLockerAlbumBinding

class LockerAlbumRecyclerAdapter(private val albumList: ArrayList<Album>) : RecyclerView.Adapter<LockerAlbumRecyclerAdapter.ViewHolder>() {

private val switchStatus = SparseBooleanArray()
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
Expand All @@ -26,6 +29,19 @@ class LockerAlbumRecyclerAdapter(private val albumList: ArrayList<Album>) : Recy
holder.binding.imgItemLockerAlbumMore.setOnClickListener {
itemClickListener.onRemoveAlbum(position)
}

val switch = holder.binding.switchRV
switch.isChecked = switchStatus[position]
switch.setOnClickListener {
if (switch.isChecked) {
switchStatus.put(position, true)
}
else {
switchStatus.put(position, false)
}

notifyItemChanged(position)
}
}

override fun getItemCount(): Int = albumList.size
Expand Down
2 changes: 1 addition & 1 deletion UMC_6th/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<SeekBar
android:id="@+id/mainSeekBar"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_height="3dp"
android:background="@null"
android:max="100000"
android:paddingStart="0dp"
Expand Down
11 changes: 11 additions & 0 deletions UMC_6th/app/src/main/res/layout/item_locker_album.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,15 @@
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>

<Switch
android:id="@+id/switchRV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:switchMinWidth="50dp"
android:switchPadding="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/imgItemLockerAlbumPlay"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 3695313

Please sign in to comment.