使用 Web 服务调用刷新列表视图,每 N 分钟刷新一次。刷新后,您的当前位置将返回到列表视图中的第一项。
以下是我的代码。
private void updateListUI(String response){
arrList = new ArrayList<Object>(); // to store array list
Object obj;
obj = some data; // some parsing of data and store in obj instance
arrList.add(obj);
if(listview.getAdapter()==null){
adapter = new customAdapter(myActivity,layout,arrList);
listview.setAdapter(adapter);
}else{
HeaderViewListAdapter adapterwrap =
(HeaderViewListAdapter) listview.getAdapter();
BaseAdapter basadapter = (BaseAdapter) adapterwrap.getWrappedAdapter();
customAdapter ad = (customAdapter)basadapter;
ad.setData(arrList); // it is a func in custom adapter that add items
ad.notifyDataSetChanged();
// here i want to set the position of list view,as it goes back to first item
}
}
BroadcastReceiver serviceReceiver = new BroadcastReceiver() {
public void onReceive( final Context context, final Intent intent ) {
updateListUI(intent.getStringExtra(response_from_service));
}
}
// Intent服务调用Web服务并在完成调用时将响应广播到接收器。我的问题是,在每次updateListUI调用时,列表视图都会回到第一个位置。有没有解决这个问题的方法..?