本文介绍了Firebase列表适配器构造函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个显示聊天消息的函数,我按照教程,我也查看了Firebase列表适配器的文档,但无论我做什么,我都会收到此错误:

I created a function to display a chat message, I followed a tutorial, and I also looked at the documentation for the Firebase list adapter, but no matter what I do, I get this error:

Error:(98, 19) error: constructor FirebaseListAdapter in class
FirebaseListAdapter<T> cannot be applied to given types;
required: FirebaseListOptions<ChatMessage>
found: Chat,Class<ChatMessage>,int,DatabaseReference
reason: actual and formal argument lists differ in length
where T is a type-variable:
T extends Object declared in class FirebaseListAdapter

这是我的代码:

private void displayChatMessage() {

    ListView listOfMessage = (ListView)findViewById(R.id.list_of_messages);

    FirebaseRecyclerOptions<ChatMessage> options =
            new FirebaseRecyclerOptions.Builder<ChatMessage>()
                    .setQuery(query, ChatMessage.class)
                    .build();
    adapter = new FirebaseListAdapter<ChatMessage, Holder>(options){
        @Override
        protected void populateView(View v, ChatMessage model, int position) {

            //Get references to the views of list_item.xml
            TextView messageText, messageUser, messageTime;
            messageText = (TextView) v.findViewById(R.id.message_text);
            messageUser = (TextView) v.findViewById(R.id.message_user);
            messageTime = (TextView) v.findViewById(R.id.message_time);

            messageText.setText(model.getMessageText());
            messageUser.setText(model.getMessageUser());
            messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)", model.getMessageTime()));

        }
    };
    listOfMessage.setAdapter(adapter);
}


推荐答案

以下是从FirebaseUI版本3.0 +暗示

删除此内容:

   adapter = new FirebaseListAdapter<ChatMessage>(this,ChatMessage.class,R.layout.list_item,FirebaseDatabase.getInstance().getReference())

您需要添加以下内容:

FirebaseListOptions<ChatMessage> options =
            new FirebaseListOptions.Builder<ChatMessage>()
                    .setQuery(query, ChatMessage.class)
                     .setLayout(android.R.layout.simple_list_item_1)
                    .build();
 adapter = new FirebaseListAdapter<ChatMessage>(options){

查询是您为列表适配器示例进行的查询:

query is the query that you make for the list adapter example:

Query query = FirebaseDatabase.getInstance().getReference().child("chats");

此处提供更多信息:

这篇关于Firebase列表适配器构造函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 01:54