Android下R.java这个类,来看看吧,或许你也有兴趣

这个问题跟Android没什么多大关系,
我们每次我们编辑res下的.xml文件后,
就会在R.java这个文件中会自动给我们生成新定义的资源的一个ID
这是怎么实现的????
怎么去监听这些.xml文件.

这个不是用java实现的 ADT插件是用java开发的吗

这个是CS的东西 生成代码 完全是ADT插件的作用 就和Eclipse可以自动为你生成get set方

法一样

监听xml文件有没有新的资源ID,有就生成新的R.java,通过java 反射实现的

楼上使用过adt吗?ADT在jdk1.6以下的版本在,会有异常,你说是什么原因呢?

我现在开发android的环境就是jdk1.6 sdk2.3 adt10没有问题

你用1.5看看,adt的xml编辑器是不好的。

你用1.5看看,adt的xml编辑器是不好用的。

应该是监控项目的一些目录下的文件, 一旦有改动就同步更新到R.java文件中去.具体怎么监控还真不了解. LZ知道后定要写个帖子广而告知哇... :D

把分给我,好吗?我不能发帖, 就是因为积分少!

这个问题我果然很感兴趣

只有在xml文件保存的时候才会去更新R.java文件吧,觉得这个保存就是一个触发时间。

呵呵,小弟只是猜测一下,哈哈 :D

这个是由ADT插件自动生成的 :o

楼主的这个问题其实涉及的Eclipse插件开发的话题,具体需要查看ADT插件的实现细节。因为Google把ADT插件也开源了,由此可以在GIT服务器上找到ResourceManager.java的源码:
[url]http://android.git.kernel.org/?p=platform/sdk.git;a=blob;f=eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceManager.java;h=e41cde54c562bb600ef4182a9307045ab6648bf1;hb=HEAD[/url]

该类的注释是:
The ResourceManager tracks resources for all opened projects.

It provide direct access to all the resources of a project as a {@link ProjectResources} object that allows accessing the resources through their file representation or as Android resources (similar to what is seen by an Android application).

The ResourceManager automatically tracks file changes to update its internal representation of the resources so that they are always up to date.

It also gives access to a monitor that is more resource oriented than the {@link GlobalProjectMonitor}.

This monitor will let you track resource changes by giving you direct access to {@link ResourceFile}, or {@link ResourceFolder}. @see ProjectResources

另外,在同一个包下的其它几个类也都与此有关,楼主可以一起研究一下。

注意ResourceManager.java中的IResourceListener接口:Interface to be notified of resource changes.