Difference between “@id/” and “@+id/” in Android

前端 未结 13 1969
悲&欢浪女
悲&欢浪女 2020-11-22 01:20

What is the diffirence between the @id/ and @+id/?

In @+id/ the plus symbol

13条回答
  •  醉话见心
    2020-11-22 02:16

    Sometimes you see references in your layout files like:

    and

    What's the difference?

    .. I'm glad you asked ☺

    @+id/foo means you are creating an id named foo in the namespace of your application. You can refer to it using @id/foo. @android:id/foo means you are referring to an id defined in the android namespace.

    The '+' means to create the symbol if it doesn't already exist. You don't need it (and shouldn't use it) when referencing android: symbols, because those are already defined for you by the platform and you can't make your own in that namespace anyway.

    This namespace is the namespace of the framework. for example, you need to use @android:id/list because this the id the framework expects to find.. (the framework knows only about the ids in the android namespace.)

    Completely copied from this source

提交回复
热议问题