'Same fragment layout different ImageView and text

I have a fragment that contains 3 different ImageButtons, that links to a new fragment with some information.

All info.fragments have the same layout, only different is the image and text.

I would like to reuse the layout on the info.fragment and pass the image and text value instead. ex. StarImage and StarText and the same with MusicImage and MusicText.

This is my first project in AndroidStudio.

startFragment and 2 info.Fragment



Solution 1:[1]

You can pass a int (or a Enum index) to your destination Fragment as a Bundle and retrieve it in your onCreateView to set your text and image according to the received number.

Check out this answer to see an example: https://stackoverflow.com/a/21486451/11407290

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Guilherme Magro