如何在Kotlin上使用Firebase UI数据库?
val adapter = FirebaseRecyclerAdapter( Discount::class.java, R.layout.fragment_main_day_item, Holder::class.java, FirebaseDatabase.getInstance().getReference() ) { override fun populateViewHolder(holder: Holder, dis: Discount, pos: Int){ } }
文档在这里
我如何使用Kotlin来处理这个问题
编辑
val mAdapter = object : FirebaseRecyclerAdapter( Chat::class.java, R.layout.fragment_main_day_item, ChatHolder::class.java, ref) { public override fun populateViewHolder(holder: ChatHolder, chat: Chat, position: Int) { } }
我把java转换成了kotlin,它可以工作。
升级到FirebaseUI 3.0后,Firebase实时数据库可与Kotlin一起使用
val options = FirebaseRecyclerOptions.Builder() .setQuery(chatQuery,Chat::class.java) .setLifecycleOwner(this) .build() val adapter = object : FirebaseRecyclerAdapter(options) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChatHolder { return ChatHolder(LayoutInflater.from(parent.context) .inflate(R.layout.row_chat, parent, false)) } protected override fun onBindViewHolder(holder: ChatHolder, position: Int, model: Chat) { holder.bind(model) } override fun onDataChanged() { // If there are no chat messages, show a view that invites the user to add a message. mEmptyListMessage.setVisibility(if (itemCount == 0) View.VISIBLE else View.GONE) } }
- android.support.v4.app.FragmentManager不能提供@ Provide或@ Produces注解的方法
- 等效的Java和Kotlin Stream代码之间意外的types差异
- Recycler中的checkbox勾选为true时,查看项目被immedietaly选中为false
- Espresso,当NestedScrollView或RecyclerView在CoordinatorLayout中时,滚动不起作用
- RecyclerView项目动画,onAnimationFinished调用,但不是onAnimationStarted。 为什么?
- Kotlin – 期待会员声明
- 我似乎无法得到我的Kotlin回收多重查看代码整理出来
- 后kotlin android片段空回收站视图
- RecyclerView在另一个RecyclerView(Mvvm + Databinding + Kotlin)
- kotlin RecyclerViewAdapter IndexOutOfBoundException
- RecyclerView粘滞页脚与DividerItemDecoration