20

What is the difference between

   setContentView(R.layout.main);

and

ArrayAdapter arrayAdapter = new ArrayAdapter(this,
                android.R.layout.simple_spinner_dropdown_item, sarray);

What is the difference between R.layout and android.R.layout?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Android
  • 8,995
  • 9
  • 67
  • 108

4 Answers4

34

R.layout.* are layouts you provide (in res/layout, for example).

android.R.layout.* are layouts that ship with the Android SDK.

synic
  • 26,359
  • 20
  • 111
  • 149
5

R.layout denotes the resources which are provided by your application. All the variables, resource files (drawable, string, layout etc) which are defined by your application can be accessed by R.

Example R.layout.*, R.drawable.*, R.id.*, R.color.*, etc

But android.R denotes the resources of your android SDK. all the resources which are not defines by you but are defined by android SDK will be available to you if you use android.R

ArrayAdapter arrayAdapter = new ArrayAdapter(this,
                android.R.layout.simple_spinner_dropdown_item, sarray);

here you have not defined an xml named simple_spinner_dropdown_item

R.layout.main denotes there an xml file whose name is main in your layout directory

Thanks Deepak

synic
  • 26,359
  • 20
  • 111
  • 149
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
2

R.layout.* is provided in our application that is built by us whereas android.R.* is something that comes with Android SDK that means they are predefined.

Lavanya
  • 3,903
  • 6
  • 31
  • 57
0
android.R.

is used for access predefined classes by android SDK (layouts/drawables)

R

is used for access custom classes(that means its layouts/drawables imported/created by user)

sasikumar
  • 12,540
  • 3
  • 28
  • 48