Для моих RecyclerView
, как я могу использовать значения Boolean
, объявленные в Fragment
, чтобы показать или скрыть различные элементы в моем шаблоне элемента RecyclerView
? В своем классе адаптеров я попытался использовать, например, holder.mIVLanguage.visibility = (myList[position].displaySymbolLanguage)
но это не сработало.
![enter image description here](https://i.stack.imgur.com/VlUeO.png)
Класс данных элемента RecyclerView
data class Facility (val arrowExpandCollapse: Drawable,
val topicSymbol: Drawable,
val displaySymbolLanguage: Boolean,
val displaySymbolPets: Boolean,
val displaySymbolVerifiedUser: Boolean,
val displaySymbolTransport: Boolean,
val displaySymbolSeating: Boolean,
val displaySymbolFingerPrint: Boolean,
val displaySymbolArrival: Boolean,
val displaySymbolDeparture: Boolean)
Класс фрагмента RecyclerView
class MyFragment : androidx.fragment.app.Fragment() {
private lateinit var mRecyclerView: RecyclerView
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_rv, container, false)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
val v = view
mRecyclerView = v!!.findViewById<RecyclerView>(R.id.my_recyclerview)
mRecyclerView.layoutManager = LinearLayoutManager(activity, RecyclerView.VERTICAL, false)
val symbolsArray = intArrayOf(R.drawable.ic_info_black_24dp,
R.drawable.ic_language_black_24dp,
R.drawable.ic_pets_black_24dp,
R.drawable.ic_language_black_24dp,
R.drawable.ic_pets_black_24dp,
R.drawable.ic_language_black_24dp,
R.drawable.ic_pets_black_24dp,
R.drawable.ic_language_black_24dp,
R.drawable.ic_pets_black_24dp,
R.drawable.ic_pets_black_24dp)
val myList = ArrayList<Facility>()
myList.add(Facility(resources.getDrawable(R.drawable.ic_keyboard_arrow_down, null),
resources.getDrawable(R.drawable.ic_info_black_24dp, null), true, false, false, false, true, true, true, false))
}
}
val mAdapter = RVAdapterFacilities(myList)
mRecyclerView.adapter = mAdapter
super.onActivityCreated(savedInstanceState)
}
}
Класс адаптера RecyclerView
class RVAdapterFacilities(val myList: ArrayList<Facility>): RecyclerView.Adapter<RVAdapterFacilities.ViewHolder>() {
override fun getItemCount(): Int {
return myList.size
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.mIVExpandCollapse.setImageDrawable(myList[position].arrowExpandCollapse)
holder.mIVTopic.setImageDrawable(myList[position].topicSymbolol)
holder.mIVLanguage.visibility = ¿What goes here?
holder.mIVPets.visibility = ¿What goes here?
holder.mIVVerifiedUser.visibility = ¿What goes here?
holder.mIVTransport.visibility = ¿What goes here?
holder.mIVSeat.visibility = ¿What goes here?
holder.mIVFingerprint.visibility = ¿What goes here?
holder.mIVDeparture.visibility = ¿What goes here?
holder.mIVArrival.visibility = ¿What goes here?
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.cv_facility_information, parent, false)
return ViewHolder(v)
}
class ViewHolder (itemView : View):RecyclerView.ViewHolder(itemView) {
val mCV = itemView.findViewById<CardView>(R.id.cv_facilities)
val mIVExpandCollapse = itemView.findViewById<ImageView>(R.id.iv_expandcollapsearrow)!!
val mIVTopic = itemView.findViewById<ImageView>(R.id.iv_topicsymbol)!!
val mLLSymbols = itemView.findViewById<LinearLayout>(R.id.ll_symbols)!!
}
}