The Android Widget Toolbox
1.TextView
2.EditText
3.Spinner
4.Button
5.CheckBox
6.RadioButton
7.DatePicker
8.TimePicker
Layouts
1.FrameLayout
2.LinearLayout
3.RelativeLayout
4.TableLayout
5.AbsoluteLayout
6.GridLayout
7.Tab Layout
Date Picker Tutorial
To provide a widget for selecting a date, use the DatePicker widget, which allows the user to
select the month, day, and year, in a familiar interface.
1.We’ll create a DatePickerDialog, which presents the date picker in a floating dialog box at the press of a button.
2.When the date is set by the user, a TextView will update with the new date.
1.Start a new project named HelloDatePicker.
2.Open the res/layout/main.xml file and insert the following:
will open the DatePickerDialog.
3. Open HelloDatePicker.java
4. add the following members to the class
5. Now we add following code in onCreate() method to capture View elements and add
listener to the Button1.First, the content is set to the main.xml layout.
2.Then the TextView and Button elements are captured from the layout with
findViewById(int).
3.A new View.OnClickListener is created for the Button, so that when it is clicked,
it will call showDialog(int), passing the unique integer ID for the date picker
dialog.
4.Using showDialog(int) allows the Activity to manage the life-cycle of the dialog
and will call the onCreateDialog(int) callback method to request the Dialog that
should be displayed.
(by clicking the "Set" button)
select the hour and minute in a familiar interface.
1.We’ll create a TimePickerDialog, which presents the date picker in a floating dialog box at the press of a button.
2.When the time is set by the user, a TextView will update with the new time.
NEXT: Spinners & Form Elements
No comments:
Post a Comment