1

I got a ListView displaying everything that is in specific category and a service that is pulling data from a web server. I am presenting a lot of data and if I pull the data anew, feed it to the adapter and notify of the data change the whole listview gets refreshed. On one side there is no issue with that, but I wish the user to maintain the same position he has left on the screen.

Is it possible to keep the same offset or insert just 1 row in a table without moving the screen to the top of the list?

1
  • How do you refresh the listview? Commented Jun 25, 2014 at 6:50

1 Answer 1

0

You need to maintain two variables one for current selected index and second for the top position of selected item from top of the list View.

int listSelectedIndex,top;

Use following method to save the current list position. You should call this method before notifying the data change.

private void saveListPosition() {

        listSelectedIndex = listView.getFirstVisiblePosition();
        View v = lstQuoteProducts.getChildAt(0);
        top = (v == null) ? 0 : v.getTop();
    }

After notify data change call following method to reset the saved position of list.

listView.setSelectionFromTop(listSelectedIndex, top);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.