Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between R.layout and android.R.layout

Tags:

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?

like image 936
Android Avatar asked Jun 22 '11 04:06

Android


People also ask

What is r in Android layout?

In Android R is an Java-class that is auto-generated from your resources by the build process. The R. layout member is a auto-generated class that contains all IDs for layouts.

What is the difference between layout and view in Android?

A layout defines the structure for a user interface in your app, such as in an activity. All elements in the layout are built using a hierarchy of View and ViewGroup objects. A View usually draws something the user can see and interact with.

What is simple_list_item_2?

simple_list_item_2 are layout which is define in android itself. in android. R. layout. simple_list_item_1 only contain only one textview but android.

What is R layout Main?

layout. main - is an integer number implemented in nested layout class of R. java class file. At the run time device will pick up their layout based on the id given in setcontentview() method.


2 Answers

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

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

like image 116
synic Avatar answered Oct 21 '22 18:10

synic


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

like image 29
Sunil Kumar Sahoo Avatar answered Oct 21 '22 18:10

Sunil Kumar Sahoo