gpt4 book ai didi

java - Firebase 列表适配器构造函数错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:01:41 24 4
gpt4 key购买 nike

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

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 是您为列表适配器示例所做的查询:

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

更多信息在这里:

Using FirebaseUI to populate a ListView

关于java - Firebase 列表适配器构造函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47243957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com