android.R -vs- R


Just a quick note - I think it might be good to warn users in a callout about the difference between R and android.R - and not to accidentally import android.R when writing the CrimeListFragment. You do mention referencing one of the list item built-in layouts earlier in the book, but when writing the sample, IDEs try to auto import classes… That can be confusing for the beginner.


Is that something IntelliJ is trying to do? I think we talk a bit about that for Eclipse, but I don’t think Eclipse is quite as aggressive about autoimport as IntelliJ is.


Yes, it is… I am using the AndroidStudio instead of eclipse on this and it is more aggressive - for some reason it wants to import android.R even though the package-less R is already visible. I lost a few hours trying to figure this out until I realized the import was up there.



Thanks for the feedback. We’ll take note of that for the next edition.


In Eclipse, if your use ctl-shift-O to have the imports added, or you put your mouse cursor over the R in the listing (when it still has a red underline), you get the option to add android.R or com.bignerdranch.Android.criminalintent.R. At first, I was a tad confused until I saw that Eclipse automatically created the package com.big… under gen to put the project’s file in. Later on, we actually use something in the system android.R file.

Another thing that took me a while to figure out (can’t remember what chapter this was in), is where the default themes and styles are, so we can see what other things we might want to change. I was able to find these links:

Android - Styles and Themes:
Android: Accessing Resources:
Android - themes.xml:
Android - styles.xml:

I am still unsure how we would actually customize things tho. Hopefully, a future chapter covers this better?


Eclipse will also silently import android.R if com.mypackage.R is not available for some reason. This doesn’t happen as often as it used to in Eclipse, thankfully, but apparently might once again pose a problem in IntelliJ.

I wish that our coverage of custom styles and themes were better than it is. It’s on my list of things to improve in the future.


I had this problem (in Android-Studio/intelliJ) recently as well. As noted before, it’s a known bug.
It (along with some other pesky bugs) seems to have disappeared with the 0.1.8 update.

Google appears to be working really hard and fast to get Studio ready for prime time, but in the meantime, remember that it’s just a “preview”.