开发者社区> 问答> 正文

SwipeRefreshLayout如何在fragment使用??报错

http://www.cnblogs.com/lwbqqyumidi/p/3637056.html 这篇博客是SwipeRefreshLayout在activity中的使用

布局文件我是直接copy

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:gravity="center"
            android:text="@string/hello_world" />
    </ScrollView>


</android.support.v4.widget.SwipeRefreshLayout>
然后是自己的代码:

public class FriendFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { 
private SwipeRefreshLayout swipeLayout;
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        
    }    
  
    @Override  
    public View onCreateView(LayoutInflater inflater, ViewGroup container,  
            Bundle savedInstanceState) {  
        View view = inflater.inflate(R.layout.fragment_friend, null);  
      
        return view;  
    }  
  
    @Override  
    public void onActivityCreated(Bundle savedInstanceState) {  
        super.onActivityCreated(savedInstanceState);  
    }  
  
    @Override  
    public void onDestroyView() {  
        super.onDestroyView();  
    }
    public void onRefresh() {
    new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        swipeLayout.setRefreshing(false);
       }
     }, 5000);
}
}  
从另一个fragment切换到这个fragment一直报错,异常代码位于View view = inflater.inflate(R.layout.fragment_friend, null); 请问这个如何解决?

附部分异常信息

展开
收起
爱吃鱼的程序员 2020-06-22 11:02:43 445 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    libs下有android-support-v4.jar木有

     Viewview=inflater.inflate(R.layout.fragment_friend,container,false); 

    这里应该是这样

    2020-06-22 11:03:02
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载