'How to search and populate an element in a specific XML layout?

I am new to Android Studio. My app is based on the Navigation Drawer Layout. I have one button for all three Fragments. This button is responsible for filling a specific TextView in the first Fragment. If I use this button in other Fragments, then my application crashes. This is because it doesn't find a similar id in the Fragment.

How can I make the TextView search and fill in a specific Fragment?



Sources

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

Source: Stack Overflow

Solution Source