 |
Q.
>Button id="@+id/cmd_play" 에서 cmd_play 이건 알겠는데 @+id 는 어떤 의미 인가요? A. 개념설명 : "@+" syntax in layout xml 정확한 의미는 아래와 같다고 보시면 됩니다. For the id attribute of a tag in XML, you should use a special syntax: "@+id/somestringvalue". The "@+" syntax creates a resource number in the R.id class, if one doesn't exist, or uses it, if it does exist. When declaring an ID value for an XML tag, use this syntax. Example: <TextView id="@+id/nameTextbox"/>, and refer to it this way in Java: findViewById(R.id.nameTextbox). All elements support the following values:
결론적으로, findViewById(R.id.string_name)의 형태로 Element를 얻기 위해서 예약된 reference entity라고 보시면 될 듯 합니다. 위에서 언급한 예문의 경우엔 "Play the music !!!" 라는 버튼이 클릭되었을 때, 해당 이벤트를 처리하기 위해선 ---------------------------------------------------------- Button button = (Button)findViewById(R.id.cmd_play); button.setOnClickListener(listenerMethod); ---------------------------------------------------------- 라는 형태로 구현이 되어야 합니다. 그러기 위해 사용되는 findViewById API를 사용하기 위해선 layout xml 문서에 <Button id="@+id/cmd_play" ....> 형태가 미리 정의되어 있어야 합니다. |
※ 회원등급 레벨 0 이상 읽기가 가능한 게시판입니다.
50
|