Android ListView add items to top without list view scroll [duplicate]

I have found solution here Retaining position in ListView after calling notifyDataSetChanged

Sorry for duplicate question.
The final code is this:

    int index = this.commentsListView.getFirstVisiblePosition() + comments.size();
    View v = this.commentsListView.getChildAt(commentsListView.getHeaderViewsCount());
    int top = (v == null) ? 0 : v.getTop();         

    this.commentsListViewAdapter.AddRangeToTop(comments);
    this.commentsListViewAdapter.notifyDataSetChanged();    

    this.commentsListView.setSelectionFromTop(index, top);

Leave a Comment