Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么直接调用刷新方法,不需要滑动才能回调 #14

Open
newbiechen1024 opened this issue Jun 12, 2016 · 2 comments
Open

Comments

@newbiechen1024
Copy link

请问有没有直接开启刷新动画的方法,不需要滑动才能刷新

@Simon-CN
Copy link

同求手动刷新方法。。。

@newbiechen1024
Copy link
Author

这个问题解决了,作者的刷新是使用Google自带的SwipeLayout的。SwipeLayout本身没有手动刷新的方法,所以只能自己弄个手动刷新。逻辑是,手动显示刷新View(就是显示刷新的小圆圈),然后进行数据加载等处理,当处理完成之后再手动将刷新View隐藏。

附上个人的解决办法:

     private PullToRefreshRecyclerView mRecyclerView;
     
     protected void onCreate(@Nullable Bundle savedInstanceState) {

          ...前面的省略

            //因为在onCreate()方法中,只是创建了SwipeLayout对象,并没有开始进行绘制,setRefreshing()方法是无效的,所以必须当SwipeLayout绘制完毕的时候,才能使用setRefreshing(),所以使用post()
            mRecyclerView.post(new Runnable() {
               @Override
               public void run() {
                   //显示刷新View
                   mRecyclerView.setRefreshing(true);
               }
            });

            //处理数据,这里举个例子
           new AsyncTask<Void,Void,Void>(){
            @Override
            protected Void doInBackground(Void... params) {
                try {
                    //异步处理数据加载
                    Thread.sleep(2000); //举例
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);

                //手动关闭刷新View
                mRecyclerView.setRefreshing(false);
                
                mRecyclerView.setOnRefreshComplete();
                mRecyclerView.onFinishLoading(true, false);
            }
        }.execute();
     }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants