0

Possible Duplicate:
Gridview Tutorial problems

In the android grid view tutorial, they use R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2, etc.

These properties are not defined in R.drawable. How does java resolve this without errors?

Community
  • 1
  • 1
user1099123
  • 6,063
  • 5
  • 30
  • 35
  • sample_0 ,sample_1,sample_2 are not properties these are images that has been used be the author who wrote tutorial add any 3 images you lie it will be resloved – Usman Kurd Jan 28 '13 at 14:16
  • http://stackoverflow.com/questions/3276260/gridview-tutorial-problems. The same question, hope it helps :) – Ahmad Jan 28 '13 at 14:21
  • Usman, I know that they are images, but still, how does java know not to complain? If I made an empty class, and called some random property, how doe sit know how to resolve it? I guess this is more of a java question than android. – user1099123 Jan 28 '13 at 14:38
  • You have to import images into the res/drawable folder (using copy and paste) named sample_0(.jpg/png), sample_1, sample_2, etc – Jonathan May 22 '17 at 19:28

1 Answers1

1

Yes, they are defined "on the fly" any time you compile your project. Go and inspect your "gen/[package]/R.java" autogenerated file, you will see something similar to:

public final class R {
    public static final class drawable {
        public static final int sample_0=0x7f020000;
        public static final int sample_1=0x7f020001;
        public static final int sample_2=0x7f020002;
    }
}  

So, when using R.drawable.sample_0 we are just making use of nested static declarations inside R class.

thelawnmowerman
  • 11,956
  • 2
  • 23
  • 36