我有以下适配器:
class HomeAdapter(val list: List<Team>, val fragment: HomeFragment) : RecyclerView.Adapter<HomeAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(fragment.context).inflate(R.layout.list_team, parent, false))
}
override fun getItemCount(): Int {
return list.size
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.position?.text = list[position].position.toString()
holder.number?.text = list[position].number
holder.name?.text = list[position].name
holder.puntuation?.text = list[position].puntuation.toString()
}
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
var view: View = v
var position: TextView? = view.findViewById(R.id.textViewPosition)
var number: TextView? = view.findViewById(R.id.textViewNumber)
var name: TextView? = view.findViewById(R.id.textViewName)
var puntuation: TextView? = view.findViewById(R.id.textViewPuntuation)
}
}
在我的片段中有以下电话:
adapter = HomeAdapter(teams, fragment!!)
if (adapter?.list!!.isNullOrEmpty()) {
image_empty?.visibility = View.VISIBLE
} else {
recycler?.adapter = adapter
}
但是没有调用我的适配器。我在做什么错了?