There are a couple of things you need to fix here. As veteran android folks will tell you, changing views of fragment from activity is not a good thing to do. Think of activity as the 'mother' of fragments it creates. If the mother starts doing the homework of its children then what's the children gonna do then? Fragment's views should be handled from inside the fragment only not outside. Further more since the fragment may not be visible in screen so the android kernel would decide to destroy it and GC it. If you keep on holding references to its view then its gonna be a waste of memory and resources.
But if you still wanna go that way then:
- Make sure your fragment is created and bound to the parent using a fragment transaction from a fragment manger. Save a reference to the fragment object in your activity object. make sure that the transaction is committed. This action will make android call the oCreateView of fragment and there you can inflate the fragment's main view. Immediately save the reference to the main fragment view in a class property variable.
- Subsequently later if you want to access the view of the fragment in your activity, call the getter for your view on the fragment's object in the activity and you are done.
But i still urge you to let fragments do their own view handling and not to mix view handling between activity and fragments and also not in between two of more fragments. that's a big design no no.