I have an ActionBarActivity
and fragment. I am using FragmentPagerAdapter
that provides fragment to my app. My question How can I access parent Activity View in Fragment ??
Simply call your parent activity using getActivity() method.
Simply declare TextView as public in fragment, initialize it by findViewById() in fragment's onCreateView(). Now by using the Fragment Object which you added in activity you can access TextView. Save this answer.
Move activity logic into a fragment With the fragment definition in place, the next step is to move the UI logic for this screen from the activity into this new fragment. If you are coming from an activity-based architecture, you likely have a lot of view creation logic happening in your activity's onCreate() function.
You can use
View view = getActivity().findViewById(R.id.viewid);
Quoting docs
Specifically, the fragment can access the Activity instance with getActivity() and easily perform tasks such as find a view in the activity layout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With