-
Use the Custom Component안드로이드/개발 팁 2014. 1. 29. 14:05
Use the Custom Component
We now have our custom component, but how can we use it? In the NotePad example, the custom component is used directly from the declarative layout, so take a look at
note_editor.xml
in theres/layout
folder.<view
class="com.android.notepad.NoteEditor$MyEditText"
id="@+id/note"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:drawable/empty"
android:padding="10dip"
android:scrollbars="vertical"
android:fadingEdge="vertical" />- The custom component is created as a generic view in the XML, and the class is specified using the full package. Note also that the inner class we defined is referenced using the
NoteEditor$MyEditText
notation which is a standard way to refer to inner classes in the Java programming language.If your custom View component is not defined as an inner class, then you can, alternatively, declare the View component with the XML element name, and exclude the
class
attribute. For example:<com.android.notepad.MyEditText
id="@+id/note"
... />Notice that the
MyEditText
class is now a separate class file. When the class is nested in theNoteEditor
class, this technique will not work. - The other attributes and parameters in the definition are the ones passed into the custom component constructor, and then passed through to the EditText constructor, so they are the same parameters that you would use for an EditText view. Note that it is possible to add your own parameters as well, and we will touch on this again below.
'안드로이드 > 개발 팁' 카테고리의 다른 글
nodemon 으로 무중단 nodejs 서버 돌리기 (0) 2022.02.15 안드로이드 퍼미션 종류 (0) 2011.05.20 이클립스 단축키 모음 (0) 2011.05.12 안드로이드에서 크기에 사용가능한 단위 (0) 2011.02.21 웹에 존재하는 파일 Stream을 이용해서 다운로드 하기 (1) 2011.02.18 - The custom component is created as a generic view in the XML, and the class is specified using the full package. Note also that the inner class we defined is referenced using the