I am trying to create an ImageView in a Fragment which will refer to the ImageView element which I have created in the XML for the Fragment. However, the findViewById<
You can call findViewById()
with the Activity Object you get inside your public void onAttach(Activity activity)
method inside your Fragment.
Save the Activity into a variable for example:
In the Fragment class:
private Activity mainActivity;
In the onAttach()
method:
this.mainActivity=activity;
Finally execute every findViewById through the vairable:
mainActivity.findViewById(R.id.TextView);