android – 将项目添加到recyclerview的顶部

我的活动中有一个Recyclerview.当我下拉它将加载新项目回收视图.
现在我需要实现pull来将概念刷新到我的recyclerview.我做到了.但是当我调用pull来刷新时,我正在获取新项目并添加到回收视图底部.我需要在循环视图的顶部添加新项目.如何将新加载的项目添加到回收站视图的顶部位置.
public void refreshing() throws IllegalStateException{

    new AsyncTask<String,Void,Void>() {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            progressBar.setVisibility(View.VISIBLE);
        }

        @Override
        protected Void doInBackground(String... arg0) {
                final List<NameValuePair> list = new ArrayList<NameValuePair>();
                list.add(new BasicNameValuePair("id",sPreferences.getString("ID","")));

                final HttpParams httpParams = new BasicHttpParams();
                HttpConnectionParams.setConnectionTimeout(httpParams,30000);
                DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);
                HttpPost httpPost = new HttpPost(Config.requestpatienthistory);
                httpPost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,false);
                try {
                    httpPost.setEntity(new UrlEncodedFormEntity(list));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                try {                       
                    HttpResponse response = httpClient.execute(httpPost);
                    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                    String json = reader.readLine();


                    JSONObject jsonObj = new JSONObject(json);
                    if (jsonObj.has("control")) {

                        JSONArray FeedArray = jsonObj.getJSONArray("control");
                        for (int i = 0; i < FeedArray.length(); i++) {
                            JSONObject FeedObj = (JSONObject) FeedArray.get(i);

                            final Historyitem item = new Historyitem();

                            if (FeedObj.has("Reported_Time")) {                                 
                                  item.setReported_Time(FeedObj.getString("Reported_Time"));                                
                            }
                            historyitems.add(item);
                        }
                    } else {
                        System.out.println("" + "no patients");
                    }
                } catch (SocketException e) {
                   e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                } catch (NullPointerException e) {
                    e.printStackTrace();
                }catch (Exception e) {
                    e.printStackTrace();                    
                }             
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            progressBar.setVisibility(View.GONE);
            historyadapter = new HistoryRecycleListAdapter(getActivity(),getActivity(),historyitems);
            hisrecyclerview.setAdapter(historyadapter);                                                
        }
    }.execute();
}

解决方法

我会坚持要在第0个位置添加项目,这个位置来自拉动刷新,如下所示,
mArrayList.add(position,item);
notifyItemInserted(position);

相关文章

以下为个人理解,如错请评 CE: 凭据加密 (CE) 存储空间, 实际路径/data/user_ce/ DE: 设备加密 (DE) 存...
转载来源:https://blog.csdn.net/yfbdxz/article/details/114702144 用EventLog.writeEvent打的日志(或...
事件分发机制详解 一、基础知识介绍 1、经常用的事件有:MotionEvent.ACTION_DOWN,MotionEvent.ACTION...
又是好久没有写博客了,一直都比较忙,最近终于有时间沉淀和整理一下最近学到和解决的一些问题。 最近进...
Android性能优化——之控件的优化 前面讲了图像的优化,接下来分享一下控件的性能优化,这里主要是面向...
android的开源库是用来在android上显示gif图片的。我在网上查了一下,大家说这个框架写的不错,加载大的...