0% found this document useful (0 votes)
34 views2 pages

Practical-N0 16

The document describes a program to implement a date picker in Android. It includes Java code to create a date picker, get the selected date, and display it in a toast message. It also includes the XML layout file to display the date picker and button.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Practical-N0 16

The document describes a program to implement a date picker in Android. It includes Java code to create a date picker, get the selected date, and display it in a toast message. It also includes the XML layout file to display the date picker and button.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

------------------------------------------------------------------------------------------

Practical No: 16
Title: Develop a program to implement Date and Time Picker
class: TYCO Roll No: 12

// Date Picker Mode

package [Link].date_picker;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

Button btn;
DatePicker dp;

@Override
protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);
setContentView([Link].activity_main);
btn=(Button)findViewById([Link]);
dp=(DatePicker)findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {

// get the values for day of month , month and


year from a date picker
String day = "Day = " + [Link]();
String month = "Month = " + ([Link]()+1);
String year = "Year = " + [Link]();
// display the values by using a toast
[Link](getApplicationContext(), day +
"\n" + month + "\n" + year, Toast.LENGTH_LONG).show();
}
});

}
}

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dp"
android:layout_centerHorizontal="true"
android:padding="20dp"
android:datePickerMode="calendar"
></DatePicker>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bt"
android:text="Submit"
android:textColor="#fff"
android:background="#150"
android:layout_marginTop="500dp"
android:layout_marginLeft="180dp"
android:textSize="20sp"
android:textStyle="bold"
></Button>

</RelativeLayout>

Fig. Date Picker

You might also like