سؤال

How do I programmatically upon inserting new items to a PullToRefreshListView scroll so that the last item is visible?

Here is some code:

listView = (PullToRefreshListView) findViewById(R.id.list);
listView.setAdapter(someAdapter);

And I would like to do:

listView.scrollToEnd();

or

someAdapter.scrollToEnd();

or something similar.

هل كانت مفيدة؟

المحلول

You can set the TranscriptMode on a ListView to have it always scroll to the bottom when new content is added

listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);

You can also use

listView.scrollTo(0, listView.getHeight());

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top