如何在Kotlin上使用Firebase UI数据库?

val adapter = FirebaseRecyclerAdapter<Discount, Holder>( 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, ChatHolder>( 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<Chat>() .setQuery(chatQuery,Chat::class.java) .setLifecycleOwner(this) .build() val adapter = object : FirebaseRecyclerAdapter<Chat, ChatHolder>(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) } }