公开辩论的太多论点get()毕加索!在com.squareup.picasso.Picasso中定义

时间:2019-01-26 07:46:44

标签: android kotlin picasso

holder.thumbnail.context引发标题错误。使用flickr API。

 override fun onBindViewHolder(holder: FlickrImageViewHolder, position: Int) {
    val photoItem = photoList[position]
    Log.d(TAG, ".onBindViewHolder: ${photoItem.title} --> $position")
    Picasso.get(holder.thumbnail.context).load(photoItem.image)
        .error(R.drawable.placeholder)
        .placeholder(R.drawable.placeholder)
        .into(holder.thumbnail)
}

.kt个完整文件

class FlickrImageViewHolder(view: View) : RecyclerView.ViewHolder(view){
var thumbnail: ImageView = view.findViewById(R.id.thumbnail)
var title: TextView = view.findViewById(R.id.title)
}
class FlickrRecyclerViewAdapter(private var photoList: List<Photo>) : RecyclerView.Adapter<FlickrImageViewHolder>() {
    private val TAG = "FlickrRecyclerViewAdapt"

override fun onCreateViewHolder(parent: ViewGroup, viewtype: Int): FlickrImageViewHolder {
    Log.d(TAG, ".onCreateViewHolder new view requested")
    val view = LayoutInflater.from(parent.context).inflate(R.layout.browse, parent, false)
    return FlickrImageViewHolder(view)
}

override fun getItemCount(): Int {
    Log.d(TAG, ".getItemCount called")
    return if (photoList.isNotEmpty()) photoList.size else 0
}

fun loadNewData(newPhotos: List<Photo>){
    photoList = newPhotos
    notifyDataSetChanged()
}

fun getPhoto(position: Int): Photo?{
    return if (photoList.isNullOrEmpty()) photoList[position] else null
}

override fun onBindViewHolder(holder: FlickrImageViewHolder, position: Int) {
    val photoItem = photoList[position]
    Log.d(TAG, ".onBindViewHolder: ${photoItem.title} --> $position")
    Picasso.get(holder.thumbnail.context).load(photoItem.image)
        .error(R.drawable.placeholder)
        .placeholder(R.drawable.placeholder)
        .into(holder.thumbnail)
}

}

0 个答案:

没有答案