Dawid Hyzy
02/10/2020, 1:15 AMdeactivateduser
02/10/2020, 2:09 AMDawid Hyzy
02/10/2020, 2:45 AMdeactivateduser
02/10/2020, 3:09 AMval res = getList()
is actually creating an object of getList named res. And, you are doing it inside your onResponse function.
Now, I believe when you want to print the value of listToko outside the class, you will do the same declaration as above. This means, you are actually creating a new object of getList. Hence, your listToko is empty as it is the default.
You can do something like below and see that your listToko is actually not empty inside your callback function.
class getList{
open var listToko: String? = ""
}
var abc = client.newCall(post).enqueue(object: Callback {
override fun onResponse(call: Call, response: Response) {
if(response.isSuccessful){
val resp = response.body?.string()
val res = getList()
res.listToko = resp
println ( res.listToko )
}
}
}
Dawid Hyzy
02/10/2020, 3:22 AM[{"kodebagian":"TRIE"},{"kodebagian":"TUOL"}]
deactivateduser
02/10/2020, 3:27 AMDawid Hyzy
02/10/2020, 3:28 AMdeactivateduser
02/10/2020, 3:30 AMDawid Hyzy
02/10/2020, 3:31 AM