How can i find where a method or a variable is used in Android Studio (shortcut)

给你一囗甜甜゛ 提交于 2020-12-29 08:48:24

问题


I know how to find the source by using ctrl + left click on a method, for example, but what if I want to find where this method is used? I'm using Windows 7.

Let's suppose I have the following method:

class A {
    public int sum(int a, int b) {
        return a+b;
    }
}

and I am using this method in

class B {
    ...
    a.sum(c, d);
    ...
}

and I want to find where I used sum while I was in class A.

PS: I'm new to Android studio (started using it about a month ago).


回答1:


In Android Studio, highlight the method and either right click > Find usages or use the Alt+F7 shortcut.

Edit: Ctrl+left click on a method is useful for finding where that method was initially declared




回答2:


For Ubuntu users:

For me Alt+F7 has not worked, so I've solved the conflict by going to the

Ubuntu System settings-> keyboard -> shortcuts

and changing Alt+F7 in there with another combination.

And now it's working ))




回答3:


Just click on the method or variable and any usages will be highlighted and on the scroll bar on the right side of your code you will see gray bars appear, those are the usages of the current highlighted (or clicked on) variable or method within your code.




回答4:


Here are different key shortcuts for displaying method or variable usage. The keymaps with F14 in them were added by me; the others are default. For Windows (and Linux?), replace the key with Ctrl (I think). Find Usages shows them in a dedicated window in Android Studio (the solution in other answers), while Show Usages puts them in a popup (second image below).




回答5:


To find all uses of a variable or method in Android Studio you can use

  1. ctrl+shift+F7(window/Ubuntu)
  2. after that for navigation purpose you can use F3



回答6:


use [Ctrl+b] or [Ctrl+Alt+b] to navigate to the origin of the method or variable declearation and implementation




回答7:


Ubuntu is Ctrl+Alt+7 or Ctrl+b to show the usage of the class. Ctrl+Alt+F7 is not work.



来源:https://stackoverflow.com/questions/29000308/how-can-i-find-where-a-method-or-a-variable-is-used-in-android-studio-shortcut

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!