I dealt a lot with the question that I had. What happens, every time an item is added to my list (adapter), I expect it to scroll automatically if I am in the last item (which it will do to some extent); HOWEVER, if 3 or more points are added immediately, it will not automatically scroll.
Here is the XML of this list:
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:transcriptMode="normal"/>
I tried a workaround using the snippet I found here .
My code is as follows:
public void addChat(final String text, final String username) {
this.runOnUiThread(new Runnable() {
public void run() {
globals.chatAdapter.add(DateFormat.format("hh:mmaa", Calendar.getInstance()).toString(), username, text);
globals.chatAdapter.notifyDataSetChanged();
int lastP = getListView().getLastVisiblePosition();
int count = globals.chatAdapter.getCount() - 1;
if (lastP == globals.chatAdapter.oldP || lastP == -1) {
getListView().setSelection(count);
}
globals.chatAdapter.oldP = count;
}
});
}
, getListView(). getLastVisiblePosition() , setSelection() , , .
?