1

I populate the list-view from Sq-lite db.Now my problem is that when i click on list-view item for going to next page and after that come back to list-view , I want the list to be scrolled to the same point that it was previously.Any idea how to do this.

This is my list-view method in

onCreate()

private void populateList() {
    descArray.clear();
    List<All_Post> allDesc = dbhelper.getAllDescriptions();
    for (All_Post all_Post : allDesc)
    {
        String strInspectorname = all_Post.getStringInspectorname();
        Log.e("strInspectorname "," = " + strInspectorname);
        descArray.add(all_Post);
    }

    if (adapter == null)
    {
        adapter = new AllPostAdapter(this, R.layout.allpostlist, descArray);
        listView.setAdapter(adapter);
    }
    else if (adapter != null) {

        adapter.notifyDataSetChanged();
        adapter = new AllPostAdapter(this, R.layout.allpostlist, descArray);
        listView.setAdapter(adapter);
    }
} 

I tried this link Maintain/Save/Restore scroll position when returning to a ListView , listView goes alwyas last position .

Community
  • 1
  • 1
p. ld
  • 585
  • 3
  • 10
  • 23

2 Answers2

1

Follow the below steps,

  1. Store your First listview Position which was clicked somewhere in Database/Shared Preference.
  2. Move to your 2nd listview.
  3. When you come back to your 1st listview just simple Get that stored value of your 1st listview position.

4. For a direct scroll:

getListView().setSelection(YOUR_POSITION);

For a smooth scroll:

getListView().smoothScrollToPosition(YOUR_POSITION); 

Hope it will help you.

Sanket Shah
  • 4,352
  • 3
  • 21
  • 41
0

Before going to the next page just store listviews's scroll position by calling either getScrollY/ getScrollX depending on your listview orientation. When you come back again to this page restore stored position by calling either setScrollX/ setScrollY

Rushikesh Talokar
  • 1,515
  • 4
  • 16
  • 32