0% found this document useful (0 votes)
200 views

PR 16 Mad

The document describes how to create a date picker and time picker in Android. It includes XML code to design the user interface with a date picker and button, and Java code to retrieve the selected date and display it in a toast message. It also includes XML and Java code for a time picker app, with code to retrieve the selected time and display it in a text view and toast.

Uploaded by

Megha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
200 views

PR 16 Mad

The document describes how to create a date picker and time picker in Android. It includes XML code to design the user interface with a date picker and button, and Java code to retrieve the selected date and display it in a toast message. It also includes XML and Java code for a time picker app, with code to retrieve the selected time and display it in a text view and toast.

Uploaded by

Megha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

MAD PR NO.16 SR.NO.

14

Develop a program to implement date and time picker.

DATE PICKRER

XML FILE:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<DatePicker

android:id="@+id/datepicker"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#EDE8E8"

android:datePickerMode="spinner"/>

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="submit"

android:layout_below="@+id/datepicker"

android:layout_centerHorizontal="true"

android:layout_marginTop="50dp"

android:textSize="20dp"/>

</RelativeLayout>

JAVA FILE:

package com.table.pr16;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
MAD PR NO.16 SR.NO.14

import android.view.View;

import android.widget.Button;

import android.widget.DatePicker;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

DatePicker dp;

Button b1;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

dp=(DatePicker) findViewById(R.id.datepicker);

b1=(Button) findViewById(R.id.button);

b1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

String day="Day="+dp.getDayOfMonth();

String month="Month="+(dp.getMonth()+1);

String year="Year="+dp.getYear();

Toast.makeText(getApplicationContext(),day+"\n"+month+"\n"+year,Toast.LENGTH_LONG).show();

});

}
MAD PR NO.16 SR.NO.14

OUTPUT:
MAD PR NO.16 SR.NO.14

Time Picker.

XML FILE:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<TimePicker

android:id="@+id/timepicker"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_marginTop="50dp"

android:background="#AE7777"

android:padding="20dp"

android:timePickerMode="spinner"/>

<TextView

android:id="@+id/textv"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="time is.."

android:textColor="#AA8DAF"

android:textStyle="bold"/>

</RelativeLayout>

JAVA FILE:

package com.table.timepicker;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
MAD PR NO.16 SR.NO.14

import android.widget.TextView;

import android.widget.TimePicker;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

TextView tv;

TimePicker tp;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

tv=(TextView) findViewById(R.id.textv);

tp=(TimePicker) findViewById(R.id.timepicker);

tp.setIs24HourView(false);

tp.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {

@Override

public void onTimeChanged(TimePicker view, int hourofday, int minute) {

Toast.makeText(getApplicationContext(),hourofday+":"+minute,Toast.LENGTH_SHORT).show();

tv.setText("time is ::"+hourofday+":"+minute);

});

OUTPUT:
MAD PR NO.16 SR.NO.14

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy