使用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));
}
}
//意向服務調用webservice和廣播響應接收器完成調用。我的問題是在每個updateListUI調用列表視圖回到第一個位置。有什麼辦法來解決這個..?刷新期間
int position = 12; // your position in listview
ListView listView = (ListView) findViewById(R.id.listView);
listView.setSelectionFromTop(position, 0);
這裏有什麼問題? –