converting activity into fragment

后端 未结 4 871
一个人的身影
一个人的身影 2020-11-27 13:11

This is a simple code to play a sound on click off a button, this code was initially written in Activity but now i want to change it to Fragments.

erro

4条回答
  •  没有蜡笔的小新
    2020-11-27 13:58

    Copy the code from the onCreate() method from the activity and paste it into the onCreateView() method of the fragment.

    To fix the errors, pass getActivity in place of this keyword and use getView().findViewById().

提交回复
热议问题