'Change activity content dynamically based on users option click in android

I have implemented below tree structure options in navigation, whenever user selects any option, I want activity content to change. Now the main challenge here is Activity content could be too big and It can include many types of fields like links, images, normal text. My purpose here is whenever user selects any option, activity will show that option related information. Now for the first option, it can have multiple images to show, text and links, second option click may not have links but it can have images, information text. Its more like XML structure will change dynamically based on user choice.

Navigation view with activity

I am new in android and I want efficient method to implement such functionality.

Below are the methods which I can think of

  1. For each option click show new activity : I can't implement this because I would have to implement this navigation option code in each activity which is too complicated for me (if anyone has any better idea to implement this approach then please let me know)
  2. Change XML content of activity dynamically : Can I do something like for each content I will write XML pages/file and change it dynamically, I would like to know how to implement this method.


Sources

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

Source: Stack Overflow

Solution Source