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

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

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

In @+id/ the plus symbol

13条回答
  •  情歌与酒
    2020-11-22 02:09

    Difference between @+id and @id is:

    • @+id is used to create an id for a view in R.java file.
    • @id is used to refer the id created for the view in R.java file.

    We use @+id with android:id="", but what if the id is not created and we are referring it before getting created(Forward Referencing).

    In that case, we have use @+id to create id and while defining the view we have to refer it.

    Please refer the below code:

    
    
         
    
       
    
    
    

    In the above code,id for Spinner @+id/spinner is created in other view and while defining the spinner we are referring the id created above.

    So, we have to create the id if we are using the view before the view has been created.

提交回复
热议问题