0

I need to add a database reference to the list adapter how do i do that from this code

private void populateTheData()
{
    ListView listView=(ListView)findViewById(R.id.lstView);
    DatabaseReference ref=FirebaseDatabase.getInstance().getReference();
    adapter=new FirebaseListAdapter<ChatMessage>(this,ChatMessage.class,R.layout.list_of_message,ref.getDatabase()){
        @Override
        protected void populateView(View v, ChatMessage model, int position) {
            TextView txtMessage=(TextView)findViewById(R.id.message_text);
            TextView txtUser=(TextView)findViewById(R.id.message_user);
            TextView txtTime=(TextView)findViewById(R.id.message_time);
            txtMessage.setText(model.getMessageText());
            txtUser.setText(model.getMessageUser());
            txtTime.setText(DateFormat.format("dd-mm-yyyy(HH:mm:ss)",model.getMessageTime()));

        }
    };
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
David Innocent
  • 606
  • 5
  • 16

1 Answers1

1

You need to change this line of code:

adapter=new FirebaseListAdapter<ChatMessage>(this,ChatMessage.class,R.layout.list_of_message,ref.getDatabase()){

with

adapter=new FirebaseListAdapter<ChatMessage>(this,ChatMessage.class,R.layout.list_of_message,ref){

Your ref variable is a DatabaseReference. I'm sure ref.getDatabase() does not return a DatabaseReference.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Error:(87, 17) error: constructor FirebaseListAdapter in class FirebaseListAdapter cannot be applied to given types; required: FirebaseListOptions found: MainActivity,Class,int,DatabaseReference reason: actual and formal argument lists differ in length where T is a type-variable: T extends Object declared in class FirebaseListAdapter – David Innocent Feb 12 '18 at 14:57
  • It's not working because another reason. The initial problem is solved. I see in this error that you are using a `FirebaseListAdapter` and not a `FirebaseListOptions` as it is found in your code. – Alex Mamo Feb 12 '18 at 15:03
  • I have found the solution https://stackoverflow.com/questions/47690974/firebaselistadapter-not-working?rq=1 – David Innocent Feb 12 '18 at 15:06