How to add retrofit response into an array.

JohnsmithDev

New member
Sep 30, 2023
1
0
1
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
}
 
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.
 

Trending Posts

Forum statistics

Threads
958,079
Messages
6,975,532
Members
3,163,986
Latest member
alee2025