1

Hey Guys I wanna Create Something like this in Recycler View

Example Step

I already has a class named HomeStep

data class HomeStep(
    val icon: Int,
    val circle: Int,
    val textName: String)

I already store icon (Green One) and circle as integer Array in string.xml

<integer-array name="icon_drawble">
    <item>@drawable/icon_1</item>
    <item>@drawable/icon_2</item>
    <item>@drawable/icon_3</item>
    <item>@drawable/icon_4</item>
</integer-array>

<integer-array name="circle_drawble">
    <item>@drawable/circle_1</item>
    <item>@drawable/circle_2</item>
    <item>@drawable/circle_3</item>
    <item>@drawable/circle_4</item>
</integer-array>

I have already stored icon and circle as string Array in string.xml also

<string-array name="list_step">
    <item>@string/step_1_text</item>
    <item>@string/step_2_text</item>
    <item>@string/step_3_text</item>
    <item>@string/step_4_text</item>
</string-array>

Is it possible to add my Integer-array and string-array in Collection ?

val listHomeStep = ArrayList<HomeStep>()
    val layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false)
    val adapter = HomeStepAdapter()

    var icon: Int
    var circle: Int
    var textName: String

    var i = 0
    while (i < listHomeStep.size) {
        icon = resources.getIntArray(R.array.icon_drawble)[i]
        circle = resources.getIntArray(R.array.circle_drawable)[i]
        textName = resources.getStringArray(R.array.list_step)[i]
        i++
    }

    listHomeStep.addAll(icon, circle, textName)
    adapter.setDataList(listHomeStep)

1 Answer 1

1

The answer is yes, you can add Integer-array or String-array to Collection

In your case, you should insert the HomeStep one by one, like this

    val listHomeStep = ArrayList<HomeStep>()
    val layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false)
    val adapter = HomeStepAdapter()

    var icon: Int
    var circle: Int
    var textName: String

    var i = 0
    while (i < listHomeStep.size) {
        icon = resources.getIntArray(R.array.icon_drawble)[i]
        circle = resources.getIntArray(R.array.circle_drawable)[i]
        textName = resources.getStringArray(R.array.list_step)[i]
        val homeStep = HomeStep(icon, circle, textName)
        listHomeStep.add(homeStep)
        i++
    }

    adapter.setDataList(listHomeStep)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.