问题描述
我有一个简单的回收器视图,它从数据库中读取一个列表,当我将它们记录到控制台时我可以看到数据,但它没有显示在回收器视图中
下面的函数在 kotlin 片段类中,用于包含回收器视图的 xml 布局
override fun onCreateView(
inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?,): View? {
// Inflate the layout for this fragment
val view: View = inflater.inflate(R.layout.fragment_chat_list,container,false)
view.recyclerView?.setHasFixedSize(true)
view.recyclerView?.layoutManager = LinearLayoutManager(context)
ref?.addChildEventListener(object : ChildEventListener {
override fun onChildAdded(snapshot: DataSnapshot,previousChildName: String?) {
val bal = snapshot.getValue<UserInfo.Uids>()
if (bal != null) {
UserInfo.Uids(bal.email,bal.uid,bal.displayName)
}
Log.d("RecyclerView",UserInfo.Uids().toString())
Log.d("RecyclerView",bal.toString())
adapter = BalAdapter(requireContext(),ArrayList<UserInfo.Uids>(),R.layout.users)
adapter!!.notifyDataSetChanged()
}
override fun onChildChanged(snapshot: DataSnapshot,previousChildName: String?) {
TODO("Not yet implemented")
}
override fun onChildRemoved(snapshot: DataSnapshot) {
TODO("Not yet implemented")
}
override fun onChildMoved(snapshot: DataSnapshot,previousChildName: String?) {
TODO("Not yet implemented")
}
override fun onCancelled(p0: DatabaseError) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
})
return view
}
-
R.layout.fragment_chat_list
是包含回收者视图标记的 xml -
R.layout.users
是数据 xml -
view.recyclerView
是回收者视图标签 -
BalAdapter
是适配器类,可以根据要求提供,但我觉得那里的代码是正确的 -
UserInfo.Uids
是数据类,包含name
和email
-
之前声明adapter
变量在override fun onCreateView
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)