如何在 Android Studio 中放置手表(查看变量是如何修改的)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25057447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to put a watch (see how a variable is modified) in Android Studio?
提问by uwe seeler
I don't know how to use a watch in Android Studio. I want to see how the value of a variable modifies through debugging. Does anyone know how to do this?
我不知道如何在 Android Studio 中使用手表。我想看看一个变量的值是如何通过调试修改的。有谁知道如何做到这一点?
回答by Miguel Lavigne
Start by putting a break point in the class where you'd want to watch a specific variable. Run the code and once it hits your breakpoint from the Variables window frame you should see all of the variables that are accessible. Simply choose the one you'd want to watch and then right click and choose "Add to watches" from the drop-down.
首先在您想要观察特定变量的类中放置一个断点。运行代码,一旦它从“变量”窗口框架命中您的断点,您应该会看到所有可访问的变量。只需选择您想观看的内容,然后右键单击并从下拉列表中选择“添加到观看”即可。
Keep debugging and you should see the variable from the Watches window frame update when appropriate based on your code.
继续调试,您应该会根据您的代码在适当的时候看到 Watches 窗口框架中的变量更新。
回答by Suragch
Assuming you have the debug tabs selected:
假设您选择了调试选项卡:
If you can't find the Watches View, it might be hiding in a few spots.
如果您找不到 Watches View,它可能隐藏在几个地方。
Check the right side:
检查右侧:
If its not there, check the left side of the Variables tab:
如果不存在,请检查变量选项卡的左侧:
And if you don't find it in those places, then you can right click one of the variables at a breakpoint and choose "Add to watches" (as described in the accepted answer). After that the Watches View should either appear or be in one of the places I described above.
如果您在这些地方没有找到它,那么您可以在断点处右键单击其中一个变量并选择“添加到手表”(如已接受的答案中所述)。之后,手表视图应该出现或位于我上面描述的地方之一。