When you needAndroidWhen exporting as a jar package, if it is useful to resources, such as R. layout and R. IDProgramWhen this package is introduced, the ID cannot be found.
This is because the R. ID in the jar has been replaced with an int constant during export, and the resource ID will be re-generated in the new program. If the two do not match, a problem will occur.
So hereAndroidThe import com. XX. r cannot be used in the project. Otherwise, a problem may occur. You must use another function to obtain its real ID when using the resource.
The solution is to use the Java reflection mechanism to locate the class through string and locate the variable value.
Method 1
Public static int GETID (context paramcontext, string paramstring1, string paramstring2) {try {class localclass = Class. forname (paramcontext. getpackagename () + ". r$ "+ paramstring1); field localfield = localclass. getfield (paramstring2); int I = integer. parseint (localfield. get (localfield. getname ()). tostring (); return I;} catch (exception localexception) {log. E ("getidbyreflection error", localexception. getmessage ();} return 0 ;}
Method 2
This is also the method to replace theme.
Public static int getlayoutresidbyname (context, string name) {return context. getresources (). getidentifier (name, "layout", context. getpackagename ();} public static int getidresidbyname (context, string name) {return context. getresources (). getidentifier (name, "ID", context. getpackagename ();} public static int getstringresidbyname (context, string name) {return context. getresources (). getidentifier (name, "string", context. getpackagename ();} public static int getdrawableresidbyname (context, string name) {return context. getresources (). getidentifier (name, "drawable", context. getpackagename ();} public static int getrawresidbyname (context, string name) {return context. getresources (). getidentifier (name, "Raw", context. getpackagename ());}
Method 3
AndroidProjects are mutually dependent and only applicable to development in eclipse.
Refer to official instructions for http: // developer.Android. Com/GUIDE/developing/projects/projects-eclipse.html