D
D
Dmistass2022-04-13 19:44:42
Android
Dmistass, 2022-04-13 19:44:42

How to correctly connect the date base in firebase for android?

How to do it right? I don't understand.

private void displayAllMessages() {
        ListView listOfMessages = findViewById(R.id.list_of_message);
        adapter = new FirebaseListAdapter<Message>(FirebaseDatabase.getInstance().getReference(), Message.class, R.layout.list_item, this) {
            @Override
            protected void populateView(@NonNull View v, @NonNull Message model, int position) {
                TextView mess_user, mess_time, mess_text;
                mess_user = v.findViewById(R.id.message_user);
                mess_time = v.findViewById(R.id.message_time);
                mess_text = v.findViewById(R.id.message_text);

                mess_user.setText(model.getUserName());
                mess_text.setText(model.getTextMessage());
                mess_time.setText(DateFormat.format("dd-mm-yyyy HH:mm:ss", model.getMassegeTime()));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2022-04-15
@Dmistass

Just the other day I ran into the same problem. The video tutorial is outdated. the way the adapter is built has changed. It turned out to dig out a certain solution (at least it worked for me).

private void displayAllMessages() {
        ListView listOfMessages = findViewById(R.id.list_of_messages);
        FirebaseListOptions<Message> options = new FirebaseListOptions.Builder<Message>()
                .setQuery(FirebaseDatabase.getInstance().getReference(), Message.class)
                .setLayout(R.layout.list_item)
                .setLifecycleOwner(this)
                .build();
        FirebaseListAdapter<Message> adapter = new FirebaseListAdapter<Message>(options) {
            @Override
            protected void populateView(@NonNull View v, @NonNull Message model, int position) {
                TextView mess_user, mess_time, mess_text;
                mess_user = v.findViewById(R.id.message_user);
                mess_time = v.findViewById(R.id.message_time);
                mess_text = v.findViewById(R.id.message_text);

                mess_user.setText(model.getUserName());
                mess_text.setText(model.getTextMessage());
                mess_time.setText(DateFormat.format("dd-mm-yyyy HH:mm", model.getMessageTime()));
            }
        };
        listOfMessages.setAdapter(adapter);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question