Search code examples
androidandroid-layouthierarchyviewer

How to find a code behind a view in hierarchyviewer


Android hierarchyviewer shows a ID for each view in the tree view. The ID is a @ sign followed by a number, e.g @4051d698

In android documentation the purpose of this number is explained as "pointer to view object".

Assuming one has the sources of a very big android project like AOSP. How can one figure out what is the java source code behind the view by using this ID?

Is there a method I can invoke that tells me what is the R.java entry that is bound to this pointer?


Solution

  • How can one figure out what is the java source code behind the view by using this ID?

    You can't, at least without a debugger. If you are used to C/C++ development, that hexadecimal value is roughly analogous to a pointer. Just because you have a pointer to a hunk of RAM in C/C++ does not mean that you can determine the source code behind the object resident at that pointer.

    Now, it is possible that there is a way in a debugger to supply this hex value and the debugger will match that up to an object and source code. I am not an Eclipse expert, or an expert on another other IDE debuggers, to know whether or not there is a means to do this. However, even if can do this, it will probably only give you the source of the class of the object (e.g., if the View is a ListView, it might send you to the ListView source code), not the source code of what created the object.

    Is there a method I can invoke that tells me what is the R.java entry that is bound to this pointer?

    First, R.java is not "bound" to any pointers.

    Second, the View in question may not have come from an inflated layout. It might have been created directly in Java code instead.

    If the View has an "View object ID" (e.g., id/content), that can better help you find where it came from, as that will be an android:id value, possibly from your layout resources.