17

Hi i am working with Gestures and i need to import but i m getting error

com.android.internal.R;

The import com.android.internal.R cannot be resolved

kindly help me , please

Mercy
  • 1,862
  • 9
  • 39
  • 75
  • How did the error prop up? Did you change anything in the project setup or added new files manually? If yes, try to clean the project and build it again. – Ahmed Faisal Dec 30 '11 at 20:01

4 Answers4

41

You don't say why you need access to com.android.internal.R, but the sad fact is that you simply cannot import it (the "internal" is a clue that it's not part of the public API). Google doesn't expose this because it is subject to change.

It is possible to get to the internal resources by calling Resources.getSystem(). To get the value of a particular resource identifier, you have to know its name and then use code like the following to find the value:

Resources res = Resources.getSystem();
int id = res.getIdentifier("resource name", "resource type", "android");

Be aware that any name that you use could disappear in future versions of Android.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • Thank you for your response! How can i get resource id this item? ``` ``` – nAkhmedov Jan 22 '18 at 13:02
  • @nAkhmedov - Your question is unclear. What you've shown is an `id` resource definition, which you can reference as `R.id.switch_widget` in code. Is there something else you have in mind? – Ted Hopp Jan 22 '18 at 14:24
5

I have a couple suggestions:

1) Make sure you don't have any other errors other than the R-related errors. Right-click your project folder in Eclipse, Android Tools -> Fix Project Properties.

2) Check to make sure you have the correct R imported. Sometimes the default Android.R can be imported.

4

Yes you can use the internal R with some dirty trick (dirty trick = Java reflection).

Just an example:

Class clasz = Class.forName("com.android.internal.R$styleable")
Field field = clasz.getDeclaredField("TextAppearance");
field.setAccessible(true);
int[] textAppearanceStyleArr = (int[])field.get(null);

field = clasz.getDeclaredField("TextAppearance_textSize");
field.setAccessible(true);
int textSizeStyle = (Integer)field.get(null);
Tim S. Van Haren
  • 8,861
  • 2
  • 30
  • 34
jmarranz
  • 6,459
  • 2
  • 21
  • 10
3

First of all, what is Gestures ? Do you have a package named com.android.internal in your gen folder ? Doest it contain R.java ? If not, try Project->Clean in Eclipse. If it still doesn't work, you may have an error in your XML layout files.

Flavian Hautbois
  • 2,940
  • 6
  • 28
  • 45