适配器呼叫:
adherenceDetails.hasFixedSize()
adherenceDetails.layoutManager= GridLayoutManager(this@PatientPlanStatus,3)
adherenceDetails.adapter= PatientPlanDetails(this@PatientPlanStatus, patientPlanAdherenceData.data?.get(0)?.adherence!!)
适配器:
class PatientPlanDetails(var mcontext: Context, var patientDatas:ArrayList<AdherencePoJo>): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun getItemCount(): Int {
return patientDatas.size
}
val TAG="PatientPlanDetails"
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
val v = LayoutInflater.from(mcontext).inflate(R.layout.patient_plan_adherence, parent, false)
return Item(v)
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
//Log.i(TAG,"On Bind")
(holder as Item).bindData(patientDatas.get(position),mcontext)
}
class Item(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindData(patienData: AdherencePoJo, context: Context) {
val TAG="PatientPlanDetails"
}
}
}
getItemCount()返回正确的大小。但只有第一行显示。请查看图片 卡片具有实际高度,但其中的项目不可见。 我也没有登录注销。