我想实现Swipe to Refresh到我的片段,它可以正常使用xml代码,但是当涉及到java代码时,我得到的错误就像Cannot resolve method 'setOnRefreshListener(anonymous android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener)'
这就是我在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);
}
});
答案 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);
}
});