1

I want to know what is the different of declaring a variable or id as

@android:id/
@+id/

When I set @+id/tabhost on Tabhost, it keep giving me error, but if I set @android:id/. it work.

NorthCat
  • 9,643
  • 16
  • 47
  • 50
PeiYu Hong
  • 83
  • 1
  • 7
  • 1
    possible duplicate of [Difference between "@id/" and "@+id/" in Android](http://stackoverflow.com/questions/5025910/difference-between-id-and-id-in-android) – Viks Apr 17 '15 at 05:03

2 Answers2

1

@+id creates a new ID. Android does not know this new ID, so the app crashes.

@id uses an existing ID from inside your app.

@android/id uses an existing ID from the Android framework. Android already knows this ID, it can access the corresponding View and the app will not crash.

ByteHamster
  • 4,884
  • 9
  • 38
  • 53
1

Resource ID in Android are specific to a your package.

@+id/name will create a resource ID in your package with the name "name" and give it a unique ID, you can also check that ID in R.java file. In code, you can use like R.id.name.

@android:id/name this will use the ID "name" from the package specified by android (in code you can use like android.R.id.name.) @android:id/ is use to get id from existing packages.

And tabhost are specified in the android package that's why its giving error @+id/tabhost ,so you have to use @android:id/

Prashant Bhoir
  • 900
  • 6
  • 8