I am trying to get a value that I passed into my adapter.
My Adapter: The line of code that matters.
class TableViewAdapter(var tripsheetlist: Tripsheetlist, driver: String) : RecyclerView.Adapter<TableViewAdapter.RowViewHolder>()
My MainActivity: The line of code that matters.
recyclerViewTripsheetlist.adapter = TableViewAdapter(tripsheetlist, driver)
private fun fetchJson() {
println("Attempting to Fetch JSON")
val url = "https://api.letsbuildthatapp.com/youtube/home_feed"
val request = Request.Builder().url(url).build()
val client = OkHttpClient()
client.newCall(request).enqueue(object: Callback {
override fun onFailure(call: Call, e: IOException) {
println("Failed to execute request") }
override fun onResponse(call: Call, response: Response) {
val body = response.body?.string()
println(body)
val gson = GsonBuilder().create()
val tripsheetlist = gson.fromJson(body, Tripsheetlist::class.java)
weightsum(tvTotalweight, tripsheetlist)
totaldelNotes(tvTotaldelv,tripsheetlist)
var driver : String = Spinner(tripsheetlist)
runOnUiThread {
recyclerViewTripsheetlist.adapter = TableViewAdapter(tripsheetlist, driver)
}
}
})
}
I have tried these in my adapter but with no luck.
val Drivers: String = driver
val Drivers: String = tripsheetlist.videos.Drivers
Not sure how to get the value passed. The drivers select them self in the spinner the selected item is passed through as driver and then this is used to filter the output of my recyclerview.
Thank you for any help.
Simple answer. I simply needed to declare my parameter.
class TableViewAdapter(var tripsheetlist: Tripsheetlist,val driver: String) : RecyclerView.Adapter<TableViewAdapter.RowViewHolder>()
I think what the problem was is that I tried to declare it inside my class and never saw a reference to it. Then when I looked I saw that tripsheet was declared as var
. So I tried it and no problems thus far.