Skip to content Skip to sidebar Skip to footer

Access Fragment View From Activity's Oncreate

I am in the process of making my first app for Android, and I have a Fragment that gets added to my Activity in the Activity's onCreate() method. The problem I am facing is that I

Solution 1:

Update your views in onCreateView().

@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, 
    Bundle savedInstanceState) {
    Viewview= inflater.inflate(R.layout.event_log, container, false);
    TextViewtv= (TextView) view.findViewById(R.id.text);
    tv.setText("hello world");
    return view;
}

Or if your changes depend on Activity your Fragment is attached to, use onActivityCreated().

@OverridepublicvoidonActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    TextViewtv= (TextView) getView().findViewById(R.id.text);
    tv.setText(getActivity.getSomeText());
}

Post a Comment for "Access Fragment View From Activity's Oncreate"