Difference between R.layout and android.R.layout

北战南征 提交于 2019-12-28 12:33:32

问题


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?


回答1:


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

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




回答2:


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 andrdoi 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




回答3:


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.




回答4:


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)



来源:https://stackoverflow.com/questions/6434970/difference-between-r-layout-and-android-r-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!