"Cannot be applied to" 在片段中 class

"Cannot be applied to" in a fragment class

我在我的APP中创建了4个tablayout,每个都有一个布局源文件和class。我还想在此片段中添加一个 SwipeRefreshLayout。 但是当我添加swipeRefreshLayout.setOnRefreshListener(getActivity());时出现了问题 而且 swipeRefreshLayout.setOnRefreshListener(this); 也不起作用.. error

片段:

public class tab_ask extends Fragment {
    public CoordinatorLayout coordinatorLayout;
    public boolean isConnected;
    public static final String NA = "NANA";
    public List<Post> postList;
    public RecyclerView recycler_post;
    public recadapter adapter;
    public SwipeRefreshLayout swipeRefreshLayout;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.tab4ask, container, false);
        recycler_post = (RecyclerView) getActivity().findViewById(R.id.recycler_post);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recycler_post.setLayoutManager(layoutManager);
        recycler_post.setItemAnimator(new DefaultItemAnimator());
        swipeRefreshLayout = (SwipeRefreshLayout) getActivity().findViewById(R.id.swipe_refresh);
        swipeRefreshLayout.setOnRefreshListener(this);
        swipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.colorAccent));
        getData();

        return rootView;
    }

}

如果您想将片段设置为监听器,您的片段应该实现 android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener