我是kotlin的新手,我有一个API,该API返回JSON,当他返回data时,他的工作正常。我想从列表视图中的URL加载徽标。但问题是午餐应用程序时图像未显示,仅数据json文本显示在列表视图中。我想通过String代码加载徽标url的方式。例
"https://www.xxxx.com/static/images/data/operators/"+code+"_logo0.png"
我尝试获取徽标的方式
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val view : View = LayoutInflater.from(context).inflate(R.layout.row_layout,parent,false)
val code = view.findViewById(R.id.code_id) as AppCompatTextView
val LogoAriline = view.findViewById(R.id.logo_image) as ImageView
code.text = list[position].logo
Picasso.get().load(Uri.parse("https://www.xxxx.com/static/images/data/operators/"+code+"_logo0.png")).into(LogoAriline)
return view as View
}
}
数据类
package com.iraqairoirt.iraqairports
data class FlightShdu (val Callsign : String, val Airline : String , val logo : String)
我只想使用URL内的航空公司代码在列表视图中显示,具体取决于数据json URL
答案 0 :(得分:1)
使用get()
并将code
更改为code.text
:
Picasso.get().load(Uri.parse("https://www.xxxx.com/static/images/data/operators/"+code.text+"_logo0.png")).into(LogoAriline)
答案 1 :(得分:1)
将Uri.parse("https://www.xxxx.com/static/images/data/operators/"+code+"_logo0.png")
替换为"https://www.xxxx.com/static/images/data/operators/"+code.text.toString()+"_logo0.png"
并将get()
替换为with(context)