How to get generic list from class and render it to your adapter?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to get generic list from class and render it to your adapter?



I have list of data that I'm getting from a remote server, the list is in a SuccessResponse class with it's type as generic, and I have a method that returns either the list or an error message based on the response that's gotten from the server. The problem I'm having is that I'm unable to find the right way to send the list to the adapter and use it so that I can show the data in the UI!



This is my SuccessResponse class:


data class SuccessResponse<T>(override val data: T) : ISuccessResponse<T>



This is my method that returns the response:


fun <E> getResponse()
: Result<ErrorResponse<MyResponse<Data>>, SuccessResponse<List<Data>?>>
return request(MyApplication().createRetrofitInstance(), it.data, MyResponse())



This is my server request class:


@GET(HEADLINE)
fun getResponse(): Call<MyResponse<Data>>



This is my activity:


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

Thread
adapter = MainAdapter(dataRemoteImpl.getResponse() , this)
runOnUiThread
my_recyclerview.layoutManager = LinearLayoutManager(this@MainActivity)
my_recyclerview.adapter = adapter

.start()





The adapter and getResponse method do not work together since it's not accepted as a parameter by the adapter and i want to have the error handling part in my getResponse method not just return a list blindly!!









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard