Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate to the corresponding java class from XML layout for fragments in Android Studio?

Suppose that I am in a layout file named "main.xml" and its corresponding fragment java class is "MainFragment.java".

Is there any shortcut to go to "MainFragment.java" from the "main.xml" or any other way?

It will be helpful to navigate around xml and java classes quickly when there are a lot of java classes and xml files in the project.

Note: For activity, there is a “C” symbol found in the top-left corner of the layout XML file. When we click that "C" symbol it will take us to corresponding java class in which the xml file is used. But for fragments, there is nothing available.

like image 936
Madhan Avatar asked Dec 19 '22 20:12

Madhan


2 Answers

Use 'Related Symbol' (Navigate -> Related Symbol...) In windows, press ctrl+alt+home, you can switch between activity/fragment and corresponding layout file

like image 74
legendmohe Avatar answered Dec 21 '22 10:12

legendmohe


You could right click on the file main.xml and in the options menu click Find Usages. You can then see all the places where main.xml is used.

like image 25
Eric B. Avatar answered Dec 21 '22 11:12

Eric B.