RefreshListView返回底部的项目不是顶部?

时间:2013-10-09 14:43:57

标签: android listadapter

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

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

1 个答案:

答案 0 :(得分:0)

如果我理解你,你可以把这个项目放在顶部,如下所示:
将项添加到ArrayList时,添加如下:

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

希望它有用 的此致