I am currently learning firebase and its implementations particularly the firebaselistadapter. I can't seem to find updated examples that work. From what I understand it works like most adapters . you need a view a model and a reference to bind the model and for adding you need to push into that same reference. I've already done custom adapters with firebase.child and it works but when I try to use it in a firebaselistadapter. it doesn't display anything plus populateview isn't called, even onerror is not called as well.
My code
FirebaseChatMessage - Custom class as model
public FirebaseChatMessage(String messageText, String messageUser) {
this.messageText = messageText;
this.messageUser = messageUser;
this.messageTime = new Date().getTime();
}
FirebaseSample.java - Activity
reference = FirebaseDatabase.getInstance().getReference().child("messages");
public void displayChat()
{
FirebaseListOptions<FirebaseChatMessage> options =
new FirebaseListOptions.Builder<FirebaseChatMessage>()
.setQuery(reference, FirebaseChatMessage.class)
.setLayout(R.layout.firebase_message)
.build();
FirebaseListAdapter<FirebaseChatMessage> adapter =
new FirebaseListAdapter<FirebaseChatMessage>(options) {
@Override
protected void populateView(View v, FirebaseChatMessage model, int position) {
Log.d(" Populating ", model.getMessageText());
TextView messageText = (TextView)v.findViewById(R.id.message_text);
TextView messageUser = (TextView)v.findViewById(R.id.message_user);
TextView messageTime = (TextView)v.findViewById(R.id.message_time);
// Set their text
messageText.setText(model.getMessageText());
messageUser.setText(model.getMessageUser());
messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)",
model.getMessageTime()));
}
@Override
public void onError(DatabaseError error) {
Log.d(" Error ", error.getDetails().toString());
}
};
}
This one under works (addValueEventListener) by the way meaning I was able to iterate over the child and return it as firebasechatmessage
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int n = 0;
for(DataSnapshot child : dataSnapshot.getChildren()) {
FirebaseChatMessage firebaseChatMessage = child.getValue(FirebaseChatMessage.class);
Log.d(" Message ", firebaseChatMessage.getMessageText());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
If anyone could help it would be very much appreciated
I also tried looking at firebase's own example i but they extended the viewholder and for now i just want to be able to have a default basic example. link