0

我在我的应用程序中使用 RefreshableListView 来刷新列表视图,它工作正常,但问题是它在列表末尾返回新项目,但我想返回顶部,请帮忙?

 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);
                }
            }
4

1 回答 1

0

如果我理解您,您可以像这样将项目放在顶部:
当您将项目添加到 ArrayList 时,像这样添加它:

myArrayList.add(0,item);// 0 is the item position

希望对您有所
帮助

于 2013-10-09T16:11:13.177 回答