-3

我在我的APP中创建了4个tablayout,每个都有一个布局源文件和类。另外我想在这个片段中添加一个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; 
    } 

} 

回答

3

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

+0

谢谢..我忘了它.. –

+0

@ X-XEON如果我的答案帮助你,请将它标记为正确 –