0% found this document useful (0 votes)
10 views6 pages

PR 16

Practical

Uploaded by

gayatriksh25
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)
10 views6 pages

PR 16

Practical

Uploaded by

gayatriksh25
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

ANDROID PRACTICAL NO : 16

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

<LinearLayout xmlns:android="[Link]

xmlns:app="[Link]

xmlns:tools="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent" tools:context=".MainActivity">

<TimePicker

android:layout_width="286dp"

android:layout_height="198dp"

android:timePickerMode="spinner" />

<TimePicker

android:id="@+id/timepicker1"

android:layout_width="296dp"

android:layout_height="153dp"

android:timePickerMode="spinner"/>

<TimePicker

android:layout_width="344dp"

android:layout_height="314dp"

android:timePickerMode="clock" />

</LinearLayout>

package [Link];

import [Link];

import [Link];

import [Link];

import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

TimePicker TP;

protected void onCreate(Bundle b) {

[Link](b);

setContentView([Link].activity_main);

TP =findViewById([Link]. timepicker1);

TP.setIs24HourView(true);

}}

PR16_2

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

<AbsoluteLayout

xmlns:android="[Link]

xmlns:tools="[Link]

xmlns:app="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent" tools:context=".MainActivity">

<EditText

android:id="@+id/in_date"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true"
android:layout_marginTop="82dp"

android:layout_x="26dp" android:layout_y="295dp"

/>

<Button

android:id="@+id/btn_date"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@+id/in_date"

android:layout_toEndOf="@+id/in_date"

android:layout_toRightOf="@+id/in_date"

android:layout_x="245dp"

android:layout_y="290dp" android:text="SELECT DATE" />

<EditText

android:id="@+id/in_time"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:layout_below="@+id/in_date"

android:layout_alignParentStart="true"

android:layout_alignParentLeft="true"

android:layout_x="28dp" android:layout_y="369dp"/>

<Button

android:id="@+id/btn_time"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/btn_date"

android:layout_alignStart="@+id/btn_date"

android:layout_alignLeft="@+id/btn_date"
android:layout_x="248dp"

android:layout_y="367dp" android:text="SELECT TIME" />

</AbsoluteLayout>

Java Code:

package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

Button btnDP,btnTP;

EditText txtDate, txtTime;

private int mYear, mMonth, mDay, mHour, mMinute;

@Override

protected void onCreate(Bundle b) {

[Link](b);

setContentView([Link].activity_main);

btnDP=findViewById([Link].btn_date);

btnTP=findViewById([Link].btn_time);

txtDate=findViewById([Link].in_date);
txtTime=findViewById([Link].in_time);

[Link](this::onClick);

[Link](this::onClick);

public void onClick(View v) {

if (v == btnDP) {

final Calendar c = [Link]();

mYear = [Link]([Link]);

mMonth =[Link]([Link]);

mDay =[Link](Calendar.DAY_OF_MONTH);

DatePickerDialog DPDialog = new DPDialog (this, new [Link]() {

@Override

public void onDateSet(DatePicker view, int year,int monthOfYear, int dayOfMonth)

[Link](dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);

}, mYear, mMonth, mDay);

[Link]();

if (v ==btnTP) {

final Calendar c = [Link]();

mHour = [Link](Calendar.HOUR_OF_DAY);

mMinute= [Link]([Link]);

TimePickerDialog tpDialog = new TimePickerDialog(this,new [Link]() {

@Override

public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

[Link](hourOfDay + ":" + minute}


},mHour, mMinute,false);

[Link]();

You might also like