如何访问Adapter中的参数
我试图获得我传递给适配器的价值。
我的适配器: 重要的代码行。
class TableViewAdapter(var tripsheetlist: Tripsheetlist, driver: String) : RecyclerView.Adapter<TableViewAdapter.RowViewHolder>()
我的主要活动: 重要的代码行。
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)
}
}
})
}
我在适配器中尝试了这些,但没有运气。
val Drivers: String = driver
val Drivers: String = tripsheetlist.videos.Drivers
不确定如何通过该值。驱动程序在旋转器中选择自己的自我,选定的项目被作为驱动程序传递,然后将其用于过滤我的回收库的输出。
谢谢您的任何帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单的回答。我只需要声明我的参数。
我认为问题在于我试图在类中声明它,但从未看到对它的引用。然后当我查看时,我看到 tripsheet 被声明为 var 。所以我尝试了一下,到目前为止没有任何问题。
Simple answer. I simply needed to declare my parameter.
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.