如何在我的应用中保存和恢复ListView滚动位置?
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);
...
}
}
答案 0 :(得分:0)
// 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);
试试这个
答案 1 :(得分:0)
Public void reset(Arralist<string> itemsList) {
this.adapterList.clear();
this.adapterList = itemList;
notifydatasetchanged();
}
在适配器类
中创建此方法并在setadapter().
yourAdapterRef.reset(itemList);
尝试这种方式它会起作用。