0

I am trying to make a chat, and when i check for new messages the List View selects the fist item.

How can i solve this? I've been looking in another Questions in Stack Overflow and others forums but without success.. For example: Maintain scroll position when adding to ListView with reverse endless-scrolling Currently i have my code like this:

int oldCount = lv.getAdapter().getCount();
View view = lv.getChildAt(0);
int pos = (view == null ? 0 : view.getBottom());

lv.setAdapter(adapter);
System.out.println("De length: " + de.length);
System.out.println(firstVisibleItem + "/" + oldCount);
for (String DE : de) {
  if (DE != null) {
    ConversaClass obj = new ConversaClass(msg[i], username, de[i], para[i]);
    adapter.add(obj);
    i++;
  }
}

//adapter.notifyDataSetChanged();
lv.setSelectionFromTop(firstVisibleItem + lv.getAdapter().getCount() - oldCount +1 , pos);

If this code is not enough feel free to ask for more. Thanks!

P.S.
  • 15,970
  • 14
  • 62
  • 86
Ko0kiE
  • 33
  • 6

1 Answers1

0

You must set transcriptMode to normal , something like this:

<ListView
    android:id="@+id/list_messages"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:transcriptMode="normal"
    android:stackFromBottom="true">
</ListView>
Rodrigo Gontijo
  • 587
  • 1
  • 9
  • 21
  • Hi, but do i need the code that i currently have? or just add android:transcriptMode="normal" will do the job? – Ko0kiE Jun 11 '17 at 13:44