- 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
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
}