适配器调用:
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()返回正确的大小。但是只显示第一行。请检查图片
卡的实际高度,但其中的物品不可见。
我在注销时也没有登录。
最佳答案
使您的 Patient_plan_adherence 布局高度为wrap_content
关于android - 为什么仅使用Recyclerview gridlayoutmanager显示第一行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45474980/