Firebaselistadapter<> Not Working
I am following this tutorial to create a chat app. This is my displayChatMessages() method: ListView listOfMessages = (ListView)findViewById(R.id.list_of_messages); adapter
Solution 1:
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:Queryquery= FirebaseDatabase.getInstance().getReference().child("chats");
//The error said the constructor expected FirebaseListOptions - here you create them:
FirebaseListOptions<ChatMessage> options = newFirebaseListOptions.Builder<ChatMessage>()
.setQuery(query, ChatMessages.class)
.setLayout(android.R.layout.message)
.build();
//Finally you pass them to the constructor here:
adapter = newFirebaseListAdapter<ChatMessages>(options){
@OverrideprotectedvoidpopulateView(View v, ChatMessages model, int position) {
// Get references to the views of message.xmlTextViewmessageText= (TextView)v.findViewById(R.id.message_text);
TextViewmessageTime= (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.
Solution 2:
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
protectedvoidpopulateView(View v, ChatMessages model, int position) {
//code here
}
};
Post a Comment for "Firebaselistadapter<> Not Working"