FirebaseListAdapter<> Not Working [duplicate]

夙愿已清 提交于 2019-12-02 09:36:15

Thanks for complete error message - this helps greatly. Based on that, I think this is what you need to do.

//Suppose you want to retrieve "chats" in your Firebase DB:
Query query = FirebaseDatabase.getInstance().getReference().child("chats");
//The error said the constructor expected FirebaseListOptions - here you create them:
FirebaseListOptions<ChatMessage> options = new FirebaseListOptions.Builder<ChatMessage>()
                    .setQuery(query, ChatMessages.class)
                     .setLayout(android.R.layout.message)
                    .build();
    //Finally you pass them to the constructor here:                
 adapter = new FirebaseListAdapter<ChatMessages>(options){
    @Override
    protected void populateView(View v, ChatMessages model, int position) {
        // Get references to the views of message.xml
        TextView messageText = (TextView)v.findViewById(R.id.message_text);
        TextView messageTime = (TextView)v.findViewById(R.id.message_time);

        // Set their text
        messageText.setText(model.getMessageBody());
        // Format the date before showing it
        messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)", model.getMessageTime()));
    }
 };

Here is an article where the same issue was encountered.

As the error says, you need FirebaseListOptions, please use this:

Query query=FirebaseDatabase.getInstance().getReference().orderByChild("name").equalTo(name);
FirebaseListOptions<ChatMessages> options = new FirebaseListOptions.Builder<ChatMessages>()
    .setQuery(query, ChatMessages.class)
    .build();

FirebaseListAdapter<ChatMessages> adapter = new FirebaseListAdapter<ChatMessages>(options) {
@Override
protected void populateView(View v, ChatMessages model, int position) {
    //code here

 }
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!