how to get a fragment added in an XML layout

ahmed picture ahmed · Dec 17, 2012 · Viewed 56.1k times · Source

I have a layout which includes a fragment as follows:

<fragment
        android:id="@+id/mainImagesList"
        android:name="com.guc.project.ImagesList"
        android:layout_width="match_parent"
        android:layout_height="62dp"
        android:layout_below="@+id/addimagebutton"
        android:layout_weight="1"
        android:paddingTop="55dp" />

now, I need to get this fragment and cast it so I can manipulate it and the updates appear. How can i do so ?!

EDIT: I think I've managed to get the fragment, but when I change some variables, the changes don't appear !

Answer

赏心悦目 picture 赏心悦目 · May 11, 2014

You can get the fragment instance as follows:

getSupportFragmentManager().findFragmentById(R.id.yourFragmentId)