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 recyclerview i dont know where im going wrong
i will post up more codes if needed
following is the code:---
class Tables : BaseClassActivity() {
lateinit var recyclerView: RecyclerView
lateinit var recyclerAdapter: TableAdapter
var Tablelist : MutableList<Tabledata> = mutableListOf()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.table_activity)
var mActionBarToolbar = findViewById<androidx.appcompat.widget.Toolbar>(R.id.toolbartable);
setSupportActionBar(mActionBarToolbar);
setScreenTitle("Tables")
recyclerView = findViewById(R.id.recyleview)
val model = ViewModelProviders.of(this)[HeroViewModel::class.java]
model.heroes?.observe(this,object :Observer<Table_response>{
override fun onChanged(t: Table_response?) {
recyclerAdapter = TableAdapter(applicationContext, Tablelist)
recyleview.layoutManager = LinearLayoutManager(applicationContext)
recyclerView.addItemDecoration(
DividerItemDecoration(
recyclerView.context,
DividerItemDecoration.VERTICAL
)
)
recyleview.adapter = recyclerAdapter }
})
}
HeroViewModel:--
class HeroViewModel : ViewModel() {
var recyclerAdapter: TableAdapter?=null
private var heroList: MutableLiveData<Table_response>? = null
val heroes: MutableLiveData<Table_response>?
get() {
//if the list is null
if (heroList == null) {
heroList = MutableLiveData<Table_response>()
//we will load it asynchronously from server in this method
loadHeroes()
}
//finally we will return the list
return heroList
}
//This method is using Retrofit to get the JSON data from URL
private fun loadHeroes() {
RetrofitClient.instance.getAllPhotos(product_category_id = "1", value = 1).enqueue(
object : Callback<Table_response> {
override fun onFailure(call: Call<Table_response>, t: Throwable) {
}
override fun onResponse(
call: Call<Table_response>,
response: Response<Table_response>
) {
if (response.body() != null) {
val res = response
heroList!!.value = response.body()
recyclerAdapter?.setMovieListItems((response.body()?.data as MutableList<Tabledata>?)!!)
}
}
})
}
}
need help thanks....
response.body()?.data as MutableList<Tabledata>
if i move this toonchanged
– Lacking