1

I am trying to maintain the scroll position of a ListView that is populated from a FirebaseListAdapter.

I have tried this stackoverflow thread but that's not to say a modification for FirebaseListAdapters may work.

private void displayChatMessages() {
    adapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class,
            R.layout.messages, FirebaseDatabase.getInstance().getReference()) {
        @Override
        protected void populateView(View v, ChatMessage model, int position) {
            // Get references to the views of message.xml
            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());
            // Format the date before showing it
            messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm)",
                    model.getMessageTime()));

        }
};

I should also note that I was unable to reference the method onViewCreated() , which one of the solutions in the aforementioned thread suggested using.

Community
  • 1
  • 1
  • Do you place it in your `Activity` or `Fragment`? As `onViewCreated()` in [this answer](http://stackoverflow.com/a/5688490/4112725) probably because they use `Fragment` – koceeng Jan 07 '17 at 02:46
  • Its placed in an Activity. In that case should it be in onCreate? – Charles Inwald Jan 07 '17 at 16:20
  • Have you tried it? Just try it first and tell us again if it doesn't work or if the error exception is changing. – koceeng Jan 08 '17 at 04:14
  • I ended up changing the UX, and the list will now just populate from the bottom and scroll to the bottom whenever the list is updated. For those interested, I used [this](http://stackoverflow.com/a/23441626/7332807). – Charles Inwald Jan 09 '17 at 15:13

0 Answers0