-1

How to save and restore ListView scroll position in my app?

public class MainActivity extends ListActivity {
    DBAdapter db;
    List<Matn> motoon;
    ListView lst;
    boolean isAll;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ...
    }
 }
Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
Mahmoud Afarideh
  • 306
  • 4
  • 20
  • Check here - http://stackoverflow.com/questions/3014089/maintain-save-restore-scroll-position-when-returning-to-a-listview?rq=1 – Amrit Pal Singh May 22 '15 at 14:25

2 Answers2

1
// save index and top position
int index = listview.getFirstVisiblePosition();
View v = listview.getChildAt(0);
int top = (v == null) ? 0 : (v.getTop() - listview.getPaddingTop());

// ...

// restore index and position
listview.setSelectionFromTop(index, top);

Try This

Abhishek Patel
  • 4,280
  • 1
  • 24
  • 38
0
Public void reset(Arralist<string> itemsList) { 

this.adapterList.clear();
this.adapterList = itemList;

notifydatasetchanged();

}

Create this method in adapter class

and call like this after setadapter().

yourAdapterRef.reset(itemList);

Try this way it will work.

gkondati
  • 516
  • 4
  • 16