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!