How to list data from an api in an Activity

Asked

Viewed 53 times

-1

Whoa, guys, good night

The thing is, I have an application in android studio where I am consuming an api through retrofit and gson, able to make all the connection and the registration functionality is working normally. The big problem is that I have a function called list where I bring the data from the api, but I can’t play that list in Activity. Follow the code.

The language is Kotlin

Here is the Activity where I implement the fun list and play this same function in the onCreate of the same Activity for when running the project already appears listed on the screen:

class Mainactivity : Appcompatactivity() {

private val clients: MutableList<Client> = mutableListOf()

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

    list()
}
fun list(){
     val clients: MutableList<Client> = mutableListOf()
     ClientWeb().list({
        clients.addAll(it)
        Toast.makeText(this, "Trouxe", Toast.LENGTH_LONG).show()
    }, {
        Toast.makeText(this, "Falha ao buscar notas", Toast.LENGTH_LONG).show()
    })

inserir a descrição da imagem aqui

  • Voce needs to put a listiview or recyclerview in its layout and send the list to one of these components , take a look at the subject adapterviews , here’s a java example for Adapter with listview https://answall.com/questions/50020/adapter-numa-listview-no-android-studio para recyclerview see here https://developer.android.com/guide/topics/ui/layout/recyclerview

1 answer

2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.