1

Possible Duplicate:
Understand the R class in Android

I cant understand why use 'R' Class in android application.

 setContentView(R.layout.main);

Can explain why use R used here.

Community
  • 1
  • 1
rejo
  • 3,352
  • 5
  • 27
  • 34

7 Answers7

16

Your question is duplicate of Understand the R class in Android

When your application is compiled, aapt generates the R class, which contains resource IDs for all the resources in your res/ directory. For each type of resource, there is an R subclass (for example, R.drawable for all drawable resources) and for each resource of that type, there is a static integer (for example, R.drawable.icon). This integer is the resource ID that you can use to retrieve your resource.

I got this detail from the below link ,check this once for more details : http://developer.android.com/guide/topics/resources/accessing-resources.html

Community
  • 1
  • 1
Nibha Jain
  • 7,742
  • 11
  • 47
  • 71
3

R.java which is Automatically System generated file it contains the id of each resources used in Application which is used to make refrence.

Ronak Mehta
  • 5,971
  • 5
  • 42
  • 69
2

R.class holds reference for all your android resources.. without which you cannot access any resources (drawable, layout, xmls etc) And R.class is Autogenerated.

Parag Chauhan
  • 35,760
  • 13
  • 86
  • 95
ngesh
  • 13,398
  • 4
  • 44
  • 60
2

R.class contains IDs for all your android resources.

Igor Popov
  • 9,795
  • 7
  • 55
  • 68
1

R is the class that contains all the resource ids for your application.

Philip Sheard
  • 5,789
  • 5
  • 27
  • 42
1

Its a resource class, contains ID for for all resources. Here you can also use

 setContentView(main);
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
Programmer
  • 5,360
  • 10
  • 37
  • 61
0

You can find more info here: http://developer.android.com/reference/android/R.html

PhatHV
  • 8,010
  • 6
  • 31
  • 40