본문 바로가기
프로그래머/프로그래밍

android:id=

by plog 2011. 6. 24.

   android:id="@+id/my_button"

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 theR.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, like so:


문자열의 시작 위치에 있는 @심볼(at-symbol)는, XML 구문분석기parser가 그것을 분석하고 ID 문자열의 나머지 부분을 확장(expand, 역주: 치환하기 위해 분리해 냄)해서, 그것을 ID 리소스로써 인식해야 한다는 것을 지시한다. +심볼(plus-symbol)은 (R.java 파일에 있는) 리소스들에 새로운 리소스 이름이 생성되어 추가되어야 한다는 것을 의미한다. 
 
 
 
 @ : 파서는 이곳이 리소스 id를 선언하는 곳임을 알게 된다.
 
 + :  id는 새로 작성되어 추가되는 리소스 이름임을 의미한다.(R.java)

안드로이드 프레임워크에 의해 제공되는 다른 많은 ID 리소스들이 있다. 안드로이드 리소스 ID를 레퍼런스할 때는, +심볼을 필요로 하지 않는다. 하지만 다음과 같이 android 패키지 네임스페이스를 추가해야 한다.

 
android:id="@android:id/empty"

이제 ID를 로컬 리소스 클래스가 아니라 android.R 리소스 클래스에서 레퍼런스한다. 
 

참고: http://www.kandroid.org/ (안드로이드 기술 커뮤니티)

댓글