Change Activity Class To Fragment
I'm pretty new new Android development. I have a class that extends Activity and I'd like to change to to a Fragment. I know as a fragment it would use onCreateView(LayoutInflater,
Solution 1:
First change this.
View rootView = inflater.inflate(R.layout.fragment_actionalerts, null);
to
View rootView = inflater.inflate(R.layout.fragment_actionalerts, container, false);
And use Fragment Context
as a getActivity()
.
Solution 2:
Try this:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.fragment_submenus_list, null);
....
return view;
}
And change every findViewById(...)
to view.findViewById(...)
Post a Comment for "Change Activity Class To Fragment"