Difference between @id/ and @+id/ in Android
you refer to Android resources
, which are already defined in Android system, with @android:id/..
while to access resources that you have defined/created in your project, you use @id/..
More Info
As per your clarifications in the chat, you said you have a problem like this :
If we use
android:id="@id/layout_item_id"
it doesn't work. Instead@+id/
works so what's the difference here? And that was my original question.
Well, it depends on the context, when you're using the XML attribute of android:id
, then you're specifying a new id, and are instructing the parser (or call it the builder) to create a new entry in R.java
, thus you have to include a +
sign.
While in the other case, like android:layout_below="@id/myTextView"
, you're referring to an id that has already been created, so parser links this to the already created id in R.java
.
More Info Again
As you said in your chat, note that android:layout_below="@id/myTextView"
won't recognize an element with id myTextView
if it is written after the element you're using it in.
What is the difference between @id and @+id?
You need to use @+id
when you are defining your own Id for a View.
Exactly from docs:
The at-symbol (@) at the beginning of the string indicates that the
XML parser should parse and expand the rest of the ID string and
identify it as an ID resource. The plus-symbol (+) means that this is
a new resource name that must be created and added to our resources
(in the R.java file). There are a number of other ID resources that
are offered by the Android framework. When referencing an Android
resource ID, you do not need the plus-symbol, but must add the android
package namespace.
Here is a practical example:
<Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/start"
/>
So here, you created two IDs
, start and check. Then, in your application you are able to connect to them with findViewById(R.id.start)
.
And this android:layout_below="@id/start"
refer to existing id.start
and means that your Button
with id check will be positioned below Button
with id start.
difference between @id and @android:id
You need to use @+id
when you are defining your own Id to a view, which in this case is section_spinner. And @android:id
is used when you need to set an Id of a view to android's pre-defined Id in framework. for e.g when using ListActivity, TabWidget/FrameLayout in TabHost and etc.
Differences between @+id , @id and @android:id
@+id/mywidget
Adds the id to R.java
@id/mywidget
References an existing id
@android:id/mywidget
References an id that exists in android.R.java, e.g. resources that are already provided by the framework
Difference between id and name attributes in HTML
The name
attribute is used when sending data in a form submission. Different controls respond differently. For example, you may have several radio buttons with different id
attributes, but the same name
. When submitted, there is just the one value in the response - the radio button you selected.
Of course, there's more to it than that, but it will definitely get you thinking in the right direction.
What is the difference between android:id=@+id/btnSet and android:id=@id/btnSet?
android:id="@+id/btnSet" means you are adding a widget or view with the name btnset in your R.java
file.
android:id="@id/btnSet" means you are using or referring an already defined widget or view with the name btnset
What is the difference between id and _id in mongoose?
From the documentation:
Mongoose assigns each of your schemas an id virtual getter by default
which returns the documents _id field cast to a string, or in the case
of ObjectIds, its hexString.
So, basically, the id
getter returns a string representation of the document's _id
(which is added to all MongoDB documents by default and have a default type of ObjectId
).
Regarding what's better for referencing, that depends entirely on the context (i.e., do you want an ObjectId
or a string
). For example, if comparing id
's, the string is probably better, as ObjectId
's won't pass an equality test unless they are the same instance (regardless of what value they represent).
Difference between id and _id fields in MongoDB
I expect it's just a typo in the documentation. The _id
field is primary key for every document. It's called _id
and is also accessible via id
. Attempting to use an id
key may result in a illegal ObjectId format
error.
That section is just indicating that the automatically generated ObjectIDs start with a timestamp so it's possible to sort your documents automatically. This is pretty cool since the _id
is automatically indexed in every collection. See http://www.mongodb.org/display/DOCS/Object+IDs for more information. Specifically under "BSON ObjectID Specification".
A BSON ObjectID is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte machine id, a 2-byte process id, and a 3-byte counter. Note that the timestamp and counter fields must be stored big endian unlike the rest of BSON.
Related Topics
Close Application and Remove from Recent Apps/
Why Are These Permissions Being Refused
Android Layout Folders: Layout, Layout-Port, Layout-Land
How to Run Media Scanner in Android
Filter Listview with Arrayadapter
Android: What Are the Recommended Configurations for Proguard
Android Install APK with Intent.View_Action Not Working with File Provider
Android: Get Height of a View Before It's Drawn
How to Implement a Contentobserver for Call Logs
How to Get the Position Selected in a Recyclerview
Transparent Alertdialog Has Black Background
Android Exception: Did You Forget to Call 'Public Void Setup (Localactivitymanager Activitygroup)'
Android - How to Enable Autostart Option Programmatically in Xiaomi Devices