View
variables of fragments can be initialised in onCreateView
method in this way.Here the TextView
is inside the fragment.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragmant_two,container,false);
if(savedInstanceState == null)
{
}
else
{
String data = savedInstanceState.getString("data");
TextView myText = (TextView)view.findViewById(R.id.text_view);
myText.setText(data);
}
return view;
}
But I found that a view is initialized inside onActivityCreated
in this way.
textView = (TextView) getActivity().findViewById(R.id.text_view);
is there any reason for which I should choose onActivityCreated
over onCreateView
?