Android - Lecture 4 (Basic Views)
Android - Lecture 4 (Basic Views)
MOBILE APPLICATION
DEVELOPMENT
By: AbuBakar Ubaid
BASIC VIEWS
Button CheckBox
EditText RadioButton
Slider Switch
android:id"=@+id/my_button"
Using the ID
• The syntax for an ID, inside an XML tag is:
android:id"=@+id/my_button"
• Referencing an Android resource ID:
android:id="@android:id/my_button"
In the layout.xml file:
<Button android:id"=@+id/my_button "
android:layout_width"=wrap_content "
android:layout_height"=wrap_content "
android:text"=@string/my_button_text/">
In the java code:
Button myButton = (Button) findViewById(R.id.my_button);
Text View
• Displays text to the user and optionally allows them to edit it
• TextView is a complete text editor, however the basic class is
configured to not allow editing
Edit Text
• EditText is a thin veneer over TextView that configures itself to be
editable
• Properties:
• capitalize to have the control capitalize words, the beginning of sentences
• phoneNumber property if you need to accept a phone number
• password property if you need a password field
• single line by setting the singleLine property to true
Button
• Button represents a push-button widget
• Push-buttons can be pressed, or clicked, by the user
to perform an action
Button XML declaration
<Button android:id="@+id/ccbtn1"
android:text="@+string/basicBtnLabel"
android:typeface="serif"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
LECTURE – 04 “Basic Views”
THANK YOU