[Android/Kotlin] ๋ฉ€ํ‹ฐ๋ทฐ ํƒ€์ž… RecyclerView ๊ตฌํ˜„ํ•˜๊ธฐ

2021. 1. 24. 02:36ใ†๐Ÿ“ฑAndroid/๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป Android ๊ฐœ๋ฐœ ์ผ์ง€

๋ฐ˜์‘ํ˜•

๋Œ€ํ•™์ƒ ๊ณต์ง€์‚ฌํ•ญ ์–ดํ”Œ - ์œ ๋‹ˆ๋ทฐ

 

์˜ค๋Š˜์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฉ€ํ‹ฐ๋ทฐ ํƒ€์ž…์˜ ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ๋ฅผ ๊ตฌํ˜„ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค !

์‚ฌ์ด๋“œ ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๋ฉด์„œ ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ์˜ ์—ฌ๋Ÿฌ itemview๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ฐพ์•„๋ณด๋˜ ์ค‘ ๋ฉ€ํ‹ฐ๋ทฐ ํƒ€์ž… ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ์ด ์กด์žฌํ•˜๋Š” ๊ฒƒ์„ ์ฒ˜์Œ ์•Œ๊ฒŒ ๋˜์—ˆ๋Š”๋ฐ์š”. 

ํ•˜๋‚˜์˜ Adapter๋ฅผ ์ด์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ View๋ฅผ ํ™œ์šฉํ•œ ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ๋ฐฐ์šธ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค!

 

๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ ๊ด€๋ จ ๋‹ค๋ฅธ ํฌ์ŠคํŒ…์ด ๊ถ๊ธˆํ•˜์‹œ๋‹ค๋ฉด !? ์•„๋ž˜ ๊ธ€์„ ๋จผ์ € ์ฝ๊ณ  ์˜ค์‹œ๋Š” ๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค!

 

[Android/Kotlin] RecyclerView ๋งŒ๋“ค๊ธฐ

์˜ค๋Š˜์€ ๊ฐ„๋‹จํ•œ ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ ์‹œ๋ฆฌ์ฆˆ 1ํƒ„์ธ RecyclerView ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์†Œ๊ฐœํ•ด๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค! RecyclerView ๋ž€?! RecyclerView๋ž€ ? ๋ฐ์ดํ„ฐ ์ง‘ํ•ฉ๋“ค์„ ๊ฐ๊ฐ์˜ ๊ฐœ๋ณ„ ์•„์ดํ…œ ๋‹จ์œ„๋กœ ๊ตฌ์„ฑํ•˜์—ฌ ํ™”๋ฉด์— ์ถœ๋ ฅํ•ด

yunaaaas.tistory.com

 

[Android/Kotlin] RecyclerView ํด๋ฆญ ์ด๋ฒคํŠธ ์ ์šฉํ•˜๊ธฐ

RecyclerView ์ฒซ๋ฒˆ์งธ ์‹œ๋ฆฌ์ฆˆ์— ์ด์–ด ๋‘๋ฒˆ์งธ ์‹œ๋ฆฌ์ฆˆ์ธ ํด๋ฆญ ๋ฆฌ์Šค๋„ˆ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ ์•„์ดํ…œ์— ๊ฐ๊ฐ ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ ์–ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค : ) RecyclerView ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€

yunaaaas.tistory.com

 

[Android/Kotlin] RecyclerView Animation ํ™œ์šฉํ•˜๊ธฐ

์ €๋ฒˆ RecyclerView ๋งŒ๋“ค๊ธฐ์™€ ClickEvent์— ์ด์–ด ํ™”๋ฉด ์ „ํ™˜์‹œ RecyclerView์— ๊ฐ„๋‹จํ•œ Animation์„ ์ ์šฉํ•ด๋ณด๋Š” ๊ฒƒ์— ๋Œ€ํ•ด ํฌ์ŠคํŒ… ํ•ด๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค. ์ €๋ฒˆ ํฌ์ŠคํŒ…๊ณผ ์ด์–ด์ง€๊ธฐ ๋•Œ๋ฌธ์— ์•„๋ž˜ ๊ธ€์„ ๋จผ์ € ์ฝ๊ณ  ์˜ค์‹œ๋Š”

yunaaaas.tistory.com

 

 


๐Ÿ“Œ RecyclerView ์•ˆ์— ๋‹ด๊ธธ Layout ๋งŒ๋“ค์–ด์ฃผ๊ธฐ

๊ฐ„๋‹จํ•˜๊ฒŒ 3๊ฐœ๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๊ฒ ์Šต๋‹ˆ๋‹ค. 

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"
    android:paddingHorizontal="20dp"
    android:paddingVertical="10dp"
    android:background="@color/purple_500"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ImageView
        android:id="@+id/img_rv_photo"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@color/black"
        android:transitionName="image"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <TextView
        android:id="@+id/tv_rv_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="์ด๋ฆ„"
        android:transitionName="name"
        android:textStyle="bold"
        android:layout_marginLeft="20dp"
        android:textSize="24sp"
        android:textColor="@color/white"
        app:layout_constraintLeft_toRightOf="@id/img_rv_photo"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/tv_rv_age"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="๋‚˜์ด"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="20dp"
        android:textSize="18sp"
        android:textColor="@color/white"
        app:layout_constraintLeft_toRightOf="@id/img_rv_photo"
        app:layout_constraintTop_toBottomOf="@id/tv_rv_name"/>


</androidx.constraintlayout.widget.ConstraintLayout>

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"
    android:paddingHorizontal="20dp"
    android:paddingVertical="10dp"
    android:background="@color/purple_500"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ImageView
        android:id="@+id/img_rv_photo"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@color/black"
        android:transitionName="image"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <TextView
        android:id="@+id/tv_rv_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="์ด๋ฆ„"
        android:transitionName="name"
        android:textStyle="bold"
        android:layout_marginRight="20dp"
        android:textSize="24sp"
        android:textColor="@color/white"
        app:layout_constraintRight_toLeftOf="@id/img_rv_photo"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/tv_rv_age"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="๋‚˜์ด"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp"
        android:textSize="18sp"
        android:textColor="@color/white"
        app:layout_constraintRight_toLeftOf="@id/img_rv_photo"
        app:layout_constraintTop_toBottomOf="@id/tv_rv_name"/>


</androidx.constraintlayout.widget.ConstraintLayout>

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"
    android:paddingHorizontal="20dp"
    android:paddingVertical="10dp"
    android:background="@color/purple_500"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ImageView
        android:id="@+id/img_rv_photo"
        android:layout_width="160dp"
        android:layout_height="160dp"
        android:src="@color/black"
        android:transitionName="image"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <TextView
        android:id="@+id/tv_rv_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="์ด๋ฆ„"
        android:transitionName="name"
        android:textStyle="bold"
        android:textSize="24sp"
        android:layout_marginVertical="20dp"
        android:textColor="@color/white"
        app:layout_constraintTop_toBottomOf="@id/img_rv_photo"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

 

๐Ÿ“Œ activity_multiview.xml

๋ฉ€ํ‹ฐ๋ทฐ ํƒ€์ž…์˜ ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ๊ฐ€ ์กด์žฌํ•˜๋Š” Activity์˜ ๋ ˆ์ด์•„์›ƒ ์ž…๋‹ˆ๋‹ค. ๊ฐ„๋‹จํ•˜๊ฒŒ RecyclerView๋งŒ ๋„ฃ์–ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".recyclerview_basic.MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/rv_profile"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        android:orientation="vertical"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

 

 

๐Ÿ“Œ data class ๋งŒ๋“ค์–ด์ฃผ๊ธฐ

๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด์„ data class๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ ์ „ type์— ๋”ฐ๋ผ ์‰ฝ๊ฒŒ view๋ฅผ ๊ตฌ๋ณ„ํ•˜๊ธฐ ์œ„ํ•ด MultiMode.kt๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

MultiMode.kt

package com.example.recyclerview_ex.recyclerview_multi

const val multi_type1 = 1
const val multi_type2 = 2
const val multi_type3 = 3

 

MultiData.kt

type์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ViewHolder๋ฅผ ์ง€์ •ํ•ด์ค˜์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— data class์— type๋„ ์ถ”๊ฐ€๋กœ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

package com.example.recyclerview_ex.recyclerview_multi

data class MultiData(
    val image : Int,
    val name : String,
    val age : Int,
    val type : Int
)

 

๐Ÿ“ŒMultiViewAdpater ๋งŒ๋“ค๊ธฐ

๋ฉ€ํ‹ฐ๋ทฐ ํƒ€์ž…์˜ ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ๋ฅผ ์œ„ํ•œ MultiviewAdapter.kt๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์ด์ „์— onCreateViewHolder์— ๊ด€ํ•œ ์„ค๋ช…์ด ํ• ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์•„๋ž˜๋Š” ๊ธฐ๋ณธ์ ์€ ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ Adpater์—์„œ ์‚ฌ์šฉํ•˜๋Š” onCreateViewHolder ์ž…๋‹ˆ๋‹ค.

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder = ViewHolder(parent.inflate(R.layout.item_recycler_ex))

 ์ด๋•Œ viewType์€ ๋ฌด์—‡์ผ๊นŒ์š”?!

viewTpye์€ ๋ณ€์ˆ˜๋ช… ๊ทธ๋Œ€๋กœ viewType์— ์˜ํ•ด ๊ตฌ๋ถ„๋˜์–ด ๋“ค์–ด์˜ค๋Š” ๊ฐ’์ž…๋‹ˆ๋‹ค.

onCreateViewHolder๊ฐ€ ํ˜ธ์ถœ ์ „ getItemViewType(position: Int) : Int ํ•จ์ˆ˜๋ฅผ ๋จผ์ € ํ˜ธ์ถœํ•˜๋ฉฐ ๋ฆฌํ„ด ๊ฐ’์ด ๋„˜๊ฒจ์ง€๋Š” ๊ฒƒ ์ž…๋‹ˆ๋‹ค.

์•„๊นŒ ์œ„์—์„œ ๋งŒ๋“  ์ „์—ญ ๋ณ€์ˆ˜์ธ MultiMode์˜ ๋ณ€์ˆ˜๊ฐ’์„ data class์— ์ €์žฅํ•ด์ค€ ์ด์œ ๊ฐ€ ๋ฐ”๋กœ ์ด๊ฒƒ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

 override fun getItemViewType(position: Int): Int {
        return datas[position].type
    }
    
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : RecyclerView.ViewHolder {
        val view : View?
        return when(viewType) {
            multi_type1 -> {
                view = LayoutInflater.from(parent.context).inflate(
                    R.layout.item_recycler_ex,
                    parent,
                    false
                )
                MultiViewHolder1(view)
            }
            multi_type2 -> {
                view = LayoutInflater.from(parent.context).inflate(
                    R.layout.item_recycler_multi1,
                    parent,
                    false
                )
                MultiViewHolder2(view)
            }
            else -> {
                view = LayoutInflater.from(parent.context).inflate(
                    R.layout.item_recycler_multi2,
                    parent,
                    false
                )
                MultiViewHolder3(view)
            }
        }
    }
    
 override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        when(datas[position].type) {
            multi_type1 -> {
                (holder as MultiViewHolder1).bind(datas[position])
                holder.setIsRecyclable(false)
            }
            multi_type2 -> {
                (holder as MultiViewHolder2).bind(datas[position])
                holder.setIsRecyclable(false)
            }
            else -> {
                (holder as MultiViewHolder3).bind(datas[position])
                holder.setIsRecyclable(false)
            }
        }
    }

 

innerclass๋กœ ๋ทฐํƒ€์ž…์— ๋งž๋Š” ViewHolder ๋งŒ๋“ค์–ด์ฃผ๊ธฐ

   inner class MultiViewHolder1(view: View) : RecyclerView.ViewHolder(view) {

        private val txtName: TextView = view.findViewById(R.id.tv_rv_name)
        private val txtAge: TextView = view.findViewById(R.id.tv_rv_age)
        private val imgProfile: ImageView = view.findViewById(R.id.img_rv_photo)

        fun bind(item: MultiData) {
            txtName.text = item.name
            txtAge.text = item.age.toString()
            Glide.with(itemView).load(item.image).into(imgProfile)

        }
    }
    inner class MultiViewHolder2(view: View) : RecyclerView.ViewHolder(view) {

        private val txtName: TextView = view.findViewById(R.id.tv_rv_name)
        private val txtAge: TextView = view.findViewById(R.id.tv_rv_age)
        private val imgProfile: ImageView = view.findViewById(R.id.img_rv_photo)

        fun bind(item: MultiData) {
            txtName.text = item.name
            txtAge.text = item.age.toString()
            Glide.with(itemView).load(item.image).into(imgProfile)

        }
    }

    inner class MultiViewHolder3(view: View) : RecyclerView.ViewHolder(view) {

        private val txtName: TextView = view.findViewById(R.id.tv_rv_name)
        private val imgProfile: ImageView = view.findViewById(R.id.img_rv_photo)

        fun bind(item: MultiData) {
            txtName.text = item.name
            Glide.with(itemView).load(item.image).into(imgProfile)

        }
    }

 

๋ทฐํƒ€์ž…์— ๋งž๊ฒŒ ๋ทฐํ™€๋”๋ฅผ ๋งŒ๋“ค์–ด ์ž˜ ์ง€์ •ํ•ด์ฃผ์—ˆ๋‹ค๋ฉด ์•„๋งˆ ์‰ฝ๊ฒŒ ๊ตฌํ˜„ํ•˜์‹ค ์ˆ˜ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

MultiviewAdapter.kt ์ „์ฒด

package com.example.recyclerview_ex.recyclerview_multi

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.recyclerview_ex.R

class MultiviewAdpater(private val context: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

    var datas = mutableListOf<MultiData>()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : RecyclerView.ViewHolder {
        val view : View?
        return when(viewType) {
            multi_type1 -> {
                view = LayoutInflater.from(parent.context).inflate(
                    R.layout.item_recycler_ex,
                    parent,
                    false
                )
                MultiViewHolder1(view)
            }
            multi_type2 -> {
                view = LayoutInflater.from(parent.context).inflate(
                    R.layout.item_recycler_multi1,
                    parent,
                    false
                )
                MultiViewHolder2(view)
            }
            else -> {
                view = LayoutInflater.from(parent.context).inflate(
                    R.layout.item_recycler_multi2,
                    parent,
                    false
                )
                MultiViewHolder3(view)
            }
        }
    }
    override fun getItemCount(): Int = datas.size

    override fun getItemViewType(position: Int): Int {
        return datas[position].type
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        when(datas[position].type) {
            multi_type1 -> {
                (holder as MultiViewHolder1).bind(datas[position])
                holder.setIsRecyclable(false)
            }
            multi_type2 -> {
                (holder as MultiViewHolder2).bind(datas[position])
                holder.setIsRecyclable(false)
            }
            else -> {
                (holder as MultiViewHolder3).bind(datas[position])
                holder.setIsRecyclable(false)
            }
        }
    }

    inner class MultiViewHolder1(view: View) : RecyclerView.ViewHolder(view) {

        private val txtName: TextView = view.findViewById(R.id.tv_rv_name)
        private val txtAge: TextView = view.findViewById(R.id.tv_rv_age)
        private val imgProfile: ImageView = view.findViewById(R.id.img_rv_photo)

        fun bind(item: MultiData) {
            txtName.text = item.name
            txtAge.text = item.age.toString()
            Glide.with(itemView).load(item.image).into(imgProfile)

        }
    }
    inner class MultiViewHolder2(view: View) : RecyclerView.ViewHolder(view) {

        private val txtName: TextView = view.findViewById(R.id.tv_rv_name)
        private val txtAge: TextView = view.findViewById(R.id.tv_rv_age)
        private val imgProfile: ImageView = view.findViewById(R.id.img_rv_photo)

        fun bind(item: MultiData) {
            txtName.text = item.name
            txtAge.text = item.age.toString()
            Glide.with(itemView).load(item.image).into(imgProfile)

        }
    }

    inner class MultiViewHolder3(view: View) : RecyclerView.ViewHolder(view) {

        private val txtName: TextView = view.findViewById(R.id.tv_rv_name)
        private val imgProfile: ImageView = view.findViewById(R.id.img_rv_photo)

        fun bind(item: MultiData) {
            txtName.text = item.name
            Glide.with(itemView).load(item.image).into(imgProfile)

        }
    }
}

 

๐Ÿ“Œ MultiViewActivity.kt

๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ์™€ Adpater๋ฅผ ์—ฐ๊ฒฐํ•ด์ฃผ๊ณ  dataclass์— ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์•„๋ž˜ ์ฝ”๋“œ๋Š” ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ ๋งŒ๋“œ๋Š” ๊ณผ์ •์—์„œ ๋‹ค๋ฃฌ ๋‚ด์šฉ์ด๋ฏ€๋กœ ์„ค๋ช…์€ ์ƒ๋žตํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

package com.example.recyclerview_ex.recyclerview_multi


import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.recyclerview_ex.HorizontalItemDecorator
import com.example.recyclerview_ex.R
import com.example.recyclerview_ex.VerticalItemDecorator
import kotlinx.android.synthetic.main.activity_main.*


class MultiviewActivity : AppCompatActivity() {
    lateinit var multiAdapter: MultiviewAdpater
    val datas = mutableListOf<MultiData>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_multiview)
        initRecycler()
    }
    private fun initRecycler() {
        multiAdapter = MultiviewAdpater(this)
        rv_profile.adapter = multiAdapter
        rv_profile.addItemDecoration(VerticalItemDecorator(10))
        rv_profile.addItemDecoration(HorizontalItemDecorator(10))


        datas.apply {
            add(MultiData(image = R.drawable.profile1, name = "mary", age = 24, multi_type3))
            add(MultiData(image = R.drawable.profile3, name = "jenny", age = 26, multi_type2))
            add(MultiData(image = R.drawable.profile2, name = "jhon", age = 27, multi_type1))
            add(MultiData(image = R.drawable.profile5, name = "ruby", age = 21, multi_type2))
            add(MultiData(image = R.drawable.profile4, name = "yuna", age = 23, multi_type3))

            multiAdapter.datas = datas
            multiAdapter.notifyDataSetChanged()

        }

    }
}

 

 

๋ - ์•„๋ž˜ ํ™”๋ฉด๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ view๊ฐ€ ์‚ฌ์šฉ๋œ ๋ฉ€ํ‹ฐ๋ทฐ ํƒ€์ž…์˜ ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ๋ฅผ ์™„์„ฑํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค : )

๋‹ค์Œ ํฌ์ŠคํŒ…์—๋Š” ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ ๋งˆ์ง€๋ง‰ ์‹œ๋ฆฌ์ฆˆ์ธ RecyclerView Swipe ์— ๋Œ€ํ•œ ๊ธ€์„ ์จ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค !

๋๊นŒ์ง€ ์ฝ์–ด๋ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

๋ฐ˜์‘ํ˜•