I am trying to access individual elements inside an object, which will then be displayed as part of the view. The goal is to have each element assigned to variables outside the object.
My adapter
private class MyCustomAdapter(list: List<Object>?, totalCount: Int): RecyclerView.Adapter<CustomViewHolder>() {
private val listings = list;
private val totalCount = totalCount;
override fun getItemCount(): Int {
if (listings != null) {
return listings.size
}
return 0
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomViewHolder {
val layoutInflater = LayoutInflater.from(parent.context);
val cellForRow = layoutInflater.inflate(R.layout.auction_main, parent, false);
return CustomViewHolder(cellForRow);
}
override fun onBindViewHolder(holder: CustomViewHolder, position: Int) {
val obj = listings?.get(position);
holder.view.textView_auction_title?.text = obj.toString()
}
}
listings?.get(position) looks like this:
{
id = 2,
title = "testtitle1",
category = pants,
}
However I am trying to display id, title and category as individual elements, rather than displaying the whole object as a text. I am very new to Kotlin so any help would be appreciated.