How to add retrofit response into an array.

JohnsmithDev

New member
Sep 30, 2023
1
0
1
Visit site
Hi, i am new to this forum. i am trying to add retrofit response into an array. i am not able to do that. please some one help me find adding retrofit response array into an array. i tried the way like below. it displays emty.

in Main.kt

Code:
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        getit()

    }
}

private fun getit():ArrayList<MyListsItem>{
    val tempList = ArrayList<MyListsItem>()
    val service = getFactory.getFact().create(SongInterface::class.java)
    GlobalScope.launch {
        val res = service.getSongs()
        res.body()?.let {
            for (item in it){
                tempList.add(MyListsItem(item.album,item.artist,item.duration,item.id,item.path,item.songuri,item.title))
            }
        }
    }
    Log.d("getall",tempList.toString())
    return tempList
}
 

B. Diddy

Senior Ambassador
Moderator
Mar 9, 2012
165,618
4,760
113
Visit site
Welcome to Android Central! I moved this from the Android Apps forum (which is for app promotion) to the Software Development forum for more specific traffic.