Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing R.java from different packages

I have an application divided in subpackages, just for personal organization:

com.myname.myapp
 |
 `-  com.myname.myapp.activities
 |
 `-  com.myname.myapp.whatever
 |
 `-  ...

The problem is that the generated R.java is located at com.myname.myapp and thus when I type R.id.something in a class from the subpackage com.myname.myapp.activities, I get R cannot be resolved to a variable (obvious I guess).

When I click on Organize imports (Ctrl+Shift+O), Eclipse fixes it adding import com.myname.myapp.R at the top, and everything seems to work perfectly. But on the other hand, Android documentation states this:

Eclipse sometimes likes to add an import android.R statement at the top of your files that use resources, especially when you ask eclipse to sort or otherwise manage imports. This will cause your make to break. Look out for these erroneous import statements and delete them

Knowing that everything is working perfectly, what should I do?

like image 390
MM. Avatar asked May 31 '11 11:05

MM.


Video Answer


1 Answers

You can import R.file where ever you want.

import com.myname.myapp.R; 

or else use at the variable like this

com.myname.myapp.R.id.test
like image 70
Kakey Avatar answered Oct 14 '22 04:10

Kakey