Android DatePicker is a widget to select date. It allows you to select date by day, month and year. Like DatePicker, android also provides TimePicker to select time.
The android.widget.DatePicker is the subclass of FrameLayout class.
Android DatePicker Example
Let’s see the simple example of datepicker widget in android.
activity_main.xml
File: activity_main.xml
android:id=“@+id/button1”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_alignParentBottom=“true”
android:layout_centerHorizontal=“true”
android:layout_marginBottom=“20dp”
android:text=“Change Date” />
<DatePicker
android:id=“@+id/datePicker”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_above=“@+id/textView1”
android:layout_centerHorizontal=“true”
android:layout_marginBottom=“36dp” />
</RelativeLayout>
Activity class
File: MainActivity.java
Output:
Leave A Comment