0

Android hierarchyviewer は、ツリー ビューで各ビューの ID を表示します。ID は、@ 記号の後に数字が続きます (例: @4051d698)

Android のドキュメントでは、この番号の目的は「ビュー オブジェクトへのポインタ」として説明されています。

AOSP のような非常に大きな Android プロジェクトのソースがあると仮定します。この ID を使用して、ビューの背後にある Java ソース コードを特定するにはどうすればよいでしょうか。

このポインターにバインドされている R.java エントリが何であるかを教えてくれる呼び出し可能なメソッドはありますか?

4

1 に答える 1

1

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.

于 2012-12-16T15:23:22.813 に答える