无法解析方法'setOnRefreshListener(anonymous android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener)'

时间:2017-04-08 03:42:22

标签: java android swipe

我想实现Swipe to Refresh到我的片段,它可以正常使用xml代码,但是当涉及到java代码时,我得到的错误就像Cannot resolve method 'setOnRefreshListener(anonymous android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener)'

enter image description here

这就是我在java代码中实现的方式

import static com.hackerinside.jaisonjoseph.polysocial.R.id.swiperefresh;

    swiperefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            //view.loadUrl("https://mbasic.facebook.com");


            view.loadUrl("https://mbasic.facebook.com/notifications");

            swiperefresh.setRefreshing(false);

        }


    });

1 个答案:

答案 0 :(得分:1)

这应该是这样的:

import android.support.v4.widget.SwipeRefreshLayout;
private SwipeRefreshLayout mswipeRefreshLayout;

mswipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

              //write your code here.
              //
                mswipeRefreshLayout.setRefreshing(false);
            }
        });