为什么在片段中没有调用我的适配器?

时间:2018-11-13 00:11:49

标签: android kotlin

我有以下适配器:

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
    }

但是没有调用我的适配器。我在做什么错了?

0 个答案:

没有答案