9

Can anyone explain from this question; whats the difference of 'R' between

R.id.myListView

&

android.R.layout.simple_list_item_1

Isn't these 2 'R' the same class?

* Some people has down voted this question. I need to ask them the reason. If you answered the duplicate question & then down voted me it would have made sense. Neither answered my question nor the duplicate one!!! I mean whats the point of down voting some one without even helping? isn't this site supposed to be for help for programmers!! Weird!! **

Shaon Hasan
  • 730
  • 7
  • 17

5 Answers5

13

R.layout.*, R.id.*,in fact any R.something without the android.- part in front of it refers to some resource in your resources folders, e.g. drawables, strings, layouts, ids of widgets etc. android.R.* refers to standard android items that come shipped with your SDK

Jamie Bull
  • 12,889
  • 15
  • 77
  • 116
thomi
  • 1,603
  • 1
  • 24
  • 31
1
R.id.myListView 

Your R.java file (Generated automatically in project/gen folder) When your application is compiled, aap 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.

android.R.layout.simple_list_item_1

For example android.R.id.text1 (in Java) is an identifier of a TextView in the Android framework. You can find it in many layouts from the framework (select_dialog_item, select_dialog_singlechoice, simple_dropdown_item_1line, etc.).

Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
Hardik Joshi
  • 9,477
  • 12
  • 61
  • 113
0

android.R is a built in set of constants provided as a part of the Android app framework. The other R class is a generated representation of your xml resources.

It is valid Java/Android to have multiple classes with the same name, as long as they are in different packages (which is the case here).

nicholas.hauschild
  • 42,483
  • 9
  • 127
  • 120
0

R.id.MyListview :- R is a class here it is your package Resource

android.R.layout.simple_list_item_1 :- it is android R/Resource class,and you are trying to use it to get layout id of simple_list_item layout

AAnkit
  • 27,299
  • 12
  • 60
  • 71
0

R.* is defined by yours. android.R.* is pre defined.

Gunaseelan
  • 14,415
  • 11
  • 80
  • 128