我已經在我的應用程序中使用RefreshableListView刷新列表視圖它工作正常,但問題是它返回列表末尾的新項目,但我想返回頂部請幫助?RefreshListView返回底部不是頂部的項目?
list.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
}
@Override
public void onRefresh(RefreshableListView listView) {
new NewDataTask().execute();// TODO Auto-generated method stub
}
});
private class NewDataTask extends AsyncTask<Void, Void, ArrayList<HashMap<String, String>>> {
@Override
protected ArrayList<HashMap<String, String>> doInBackground(Void... params) {
new_request_feeds("my url"); //method which return json from the url
return fetch;
}
@Override
protected void onPostExecute(ArrayList<HashMap<String, String>> fetch) {
// This should be called after refreshing finished
if(fetch.size()!=0)
{
adapter=new CustomListAdapter(getActivity(), R.id.list_ongoing, fetch);
list.setAdapter(adapter);
}
else
{
System.out.println("no feeds");
Toast.makeText(getActivity(), "no feeds", 3000).show();
}// Here if you wish to do future process for ex. move to another activity do here
list.completeRefreshing();
super.onPostExecute(result);
}
}
你在哪裏添加新值 – r4jiv007
doinbackgroung將返回一個名爲fetch的數組列表,並且我將這個數據提交到onpostexecute內部的自定義列表適配器中,以便用位於提取中的新數據再次設置列表。 –
嘗試在arraylist中的初始索引處添加數據..應該可以工作 – r4jiv007