开发者

How do I prevent listview from scrolling to the top after using setAdapter

开发者 https://www.devze.com 2023-03-26 23:52 出处:网络
I have a listview that switches between a few custom lists. I press a button to toggle between the开发者_C百科 different adapters in my listview but it jumps to the top of the listview. Is there a way

I have a listview that switches between a few custom lists. I press a button to toggle between the开发者_C百科 different adapters in my listview but it jumps to the top of the listview. Is there a way I can stay in the same position on the screen as I switch between lists?


don't use set adapter to update content , use notifyDatasetChanged istead

     if(listView.getAdapter()==null)
       listView.setAdapter(myAdapter);
    else{
       //update the adapter data

       myAdapter.notifyDatasetChanged();
    }

that should work


Use any of these 2:

1. Call getListView().setSelection(int iIndex);
2. Call getListView().smoothScrollToPosition();

Kindly let me know, if any of these works.

0

精彩评论

暂无评论...
验证码 换一张
取 消