how to set setContentView in fragment

前端 未结 4 464
慢半拍i
慢半拍i 2021-01-27 05:37

I am trying to call a library in a fragment but dont know how to set it in a fragment I have done it in the main activity but I am getting an error in setting the setContentVie

4条回答
  •  爱一瞬间的悲伤
    2021-01-27 06:01

    setContentView() is for Activities, for Fragments you have to return the inflated layout on the onCreateView() method like this:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.article_view, container, false);
    }
    

    I hope it helps.

提交回复
热议问题