Skip to content Skip to sidebar Skip to footer

List Is Not Getting In Recyclerview Using Retrofit

basically im trying display list in recyclerview using retrofit and viewmodel........ on debugging the onresponse im getting 200 response but why is it not displaying list in recyc

Solution 1:

You are passing empty list every time you have onChanged() callback in your Activity, and you are trying to set the response on TableAdapter from ViewModel that is never created. You shouldn't do this, what you should do is you should move this code:

recyclerAdapter?.setMovieListItems((response.body()?.dataas MutableList<Tabledata>?)!!)

in here:

model.heroes?.observe(this,object :Observer<Table_response>{
        overridefunonChanged(t: Table_response?) {
            recyclerAdapter = TableAdapter(applicationContext, Tablelist)
            recyleview.layoutManager = LinearLayoutManager(applicationContext)
            recyclerView.addItemDecoration(
                DividerItemDecoration(
                    recyclerView.context,
                    DividerItemDecoration.VERTICAL
                )
            )
            
            recyclerAdapter.setMovieListItems(t?.dataas MutableList<Tabledata>?)
            recyleview.adapter = recyclerAdapter            }

    })

And remove the adapter from ViewModel.

Post a Comment for "List Is Not Getting In Recyclerview Using Retrofit"