Android Studio Is It Normal For R.id To Access Every Components
Solution 1:
Yes. R.id
will contain every single id defined in your app. Each id is just a number, and many of them are not used in any given activity or layout.
Solution 2:
R.java
is a generated file containing all the resource identifiers for your application.
R.id
is just one subclass. You also would see R.layout
auto-complete, for example on setContentView
The auto-completion will pull everything because there is no isolation inside of activities, fragments, services, etc.
(snippet of mine)
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/publicfinalclassR {
// ...publicstaticfinalclassid {
publicstaticfinalint action0=0x7f0e0090;
publicstaticfinalint action_bar=0x7f0e0060;
publicstaticfinalint action_bar_activity_content=0x7f0e0000;
publicstaticfinalint action_bar_container=0x7f0e005f;
publicstaticfinalint action_bar_root=0x7f0e005b;
publicstaticfinalint action_bar_spinner=0x7f0e0001;
publicstaticfinalint action_bar_subtitle=0x7f0e0041;
Solution 3:
Your question been asked so even before I thought to learn android. Android: What is R? Why is it so Cryptic?
R
is a class containing the definitions for all resources of a particular application package. It is in the namespace of the application package.For example, if you say in your manifest your package name is
com.foo.bar
, anR
class is generated with the symbols of all your resources incom.foo.bar.R
.There are generally two
R
classes you will deal with
- The framework resources in
android.R
and- Your own in your namespace
It is named
R
because that stands for Resources, and there is no point in making people type something longer, especially since it is common to end up with fairly long symbol names after it, that can cause a fair amount of line wrapper.
Now in my words,
If we are referencing our own resources that you have created, mostaly we use R.
So android studio gives us suggestions based on that.
You should have also noticed android.R
which is meant for utilizing resources built in to the operating system.
So yes you will get suggestions based on which R
you use and now you should know suggestions based on that R
is not for a particular Activity or view that's the reason it suggests them all.
Also there is an article, you can gain more knowledge about R.java
, android.R
and resources.
Post a Comment for "Android Studio Is It Normal For R.id To Access Every Components"