[go: up one dir, main page]

0% found this document useful (0 votes)
16 views9 pages

Practical No 16

The document outlines a practical exercise for developing a program that implements Date and Time Pickers in Android applications. It details the significance, relevant program outcomes, required competencies, and practical outcomes, along with theoretical background and resources needed. Additionally, it includes example code for creating TimePicker and DatePicker functionalities, as well as an assessment scheme for evaluating student performance.
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)
16 views9 pages

Practical No 16

The document outlines a practical exercise for developing a program that implements Date and Time Pickers in Android applications. It details the significance, relevant program outcomes, required competencies, and practical outcomes, along with theoretical background and resources needed. Additionally, it includes example code for creating TimePicker and DatePicker functionalities, as well as an assessment scheme for evaluating student performance.
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/ 9

Mobile Application Development (22617) Practical No.

16

Practical No. 16: Develop a program to implement Date and Time Picker

I. Practical Significance
Android provides controls for the user to pick a time or pick a date as ready-to-use dialogs.
Each picker provides controls for selecting each part of the time (hour, minute, AM/PM) or
date (month, day, year). Using these pickers helps ensure that your users can pick a time or
date that is valid, formatted correctly, and adjusted to the user's locale.

II. Relevant Program Outcomes (POs)


PO 2- Discipline knowledge
PO 3- Experiments and practice
PO 4- Engineering tools

III. Competency and Skills


“Create simple Android applications.”
This practical is expected to develop the following skills
1. Use time picker to display the time either in 24 Hour format or 12 Hour format.
2. Use Date picker to display the date.

IV. Relevant Course Outcome(s)


1. Develop rich user Interfaces by using layouts and controls.
2. Use User Interface components for android application development.

V. Practical Outcomes (PrOs)


1. Develop a program to display a date using Date picker.
2. Develop a program to display a time using Time picker.

VI. Relevant Affective Domain Related Outcome(s)


1. Work collaboratively in team
2. Follow ethical practices

VII. Minimum Theoretical Background Date Picker:


Android Date Picker allows you to select the date consisting of day, month and year in your custom
user interface. For this functionality android provides DatePicker and DatePickerDialog
components.

Maharashtra State Board of Technical Education 1


Mobile Application Development (22617) Practical No. 16

Time Picker:
Android Time Picker allows you to select the time of day in either 24 hour or AM/PM mode.
The time consists of hours, minutes and clock format. Android provides this functionality
through TimePicker class. Following xml attribute is used to create time picker.

VIII. Resources required (Additional)


Sr. Instrument /Object Specification Quantity Remarks
No.
Android enabled 2 GB RAM 1 Data cable is
smartphone / Android mandatory for
1
version supporting emulators
emulator

IX. Practical Related Questions


Note: Below given are few sample questions for reference. Teachers must design more
such questions to ensure the achievement of identified CO.
1. Write an xml Timepicker tag with all its attributes.
2. List and explain all methods of TimePickerclass
3. List and explain any five methods of DatePickerclass
(Space for answers)
1.
android:timePickerMode Defines the look of the widget, can be “clock” or “spinner”
Inherited XML attributes
• From class android.widget.FrameLayout
• From class android.view.ViewGroup
• From class android.view.View

<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner" />

Maharashtra State Board of Technical Education 2


Mobile Application Development (22617) Practical No. 16

2. TimePicker
i. setHour(Integer Hour):
This method is used to set the current hours in a time picker.
ii. getHour():
This method is used to get the current hours from a time picker.
iii. setMinute(int minute)
Sets the currently selected minute.
iv. getMinute():
This method is used to get the current minutes from a time picker.
v. setIs24HourView(Boolean is24HourView):
This method is used to set the mode of the Time picker either 24 hour mode or AM/PM mode.
vi. is24HourView()
vii. setOnTimeChangedListener(TimePicker.OnTimeChangedListener onTimeChangedListener)
Set the callback that indicates the time has been adjusted by the user.

3. DatePicker methods:
i. setSpinnersShown(boolean shown):
This method is used to set whether the spinner of the date picker in shown or not. In this
method you have to set a Boolean value either true or false. True indicates spinner is shown,
false value indicates spinner is not shown. Default value for this function is true.
ii. getDayOfMonth():
This method is used to get the selected day of the month from a date picker. This method
returns an integer value.
iii. getMonth():
This method is used to get the selected month from a date picker. This method returns an
integer value.
iv. getYear():
This method is used to get the selected year from a date picker. This method returns an integer
value.
v. getFirstDayOfWeek():
This method is used to get the first day of the week. This method returns an integer value.

X. Exercise
(Use blank space provide for answers or attached more pages if needed)
1. Write a program to display following output. Use TimePicker with Spinnermode.

Maharashtra State Board of Technical Education 3


Mobile Application Development (22617) Practical No. 16

2. Write a program to display following output. Select and display date and time on click of
“select date”, “select time” buttons respectively.

(Space for answers)


1.
MainActivity.java
package com.jpa.experiment16_1;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TimePicker;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Maharashtra State Board of Technical Education 4


Mobile Application Development (22617) Practical No. 16

TimePicker tp1= (TimePicker) findViewById(R.id.timePicker1);


tp1.setIs24HourView(false);
TimePicker tp2= (TimePicker) findViewById(R.id.timePicker2);
tp2.setIs24HourView(true);
}
}

//=================================================================
activity_main.xml
<?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/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner"
android:layout_margin="10dp"
android:background="#f77"/>
<TimePicker
android:id="@+id/timePicker2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:timePickerMode="spinner"
android:layout_toRightOf="@+id/timePicker1"
android:background="#77ffff"/>

<TimePicker
android:id="@+id/timePicker3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/timePicker1"

Maharashtra State Board of Technical Education 5


Mobile Application Development (22617) Practical No. 16

android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:timePickerMode="clock" />

</RelativeLayout>

//=================================================================
2.
MainActivity.java
package com.jpa.experiment16_2;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class MainActivity extends AppCompatActivity {


EditText et1, et2;
Button b1,b2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1 = findViewById(R.id.editTextDate);
et2 = findViewById(R.id.editTextTime);
b1 = findViewById(R.id.button1);
b2 = findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
@Override

Maharashtra State Board of Technical Education 6


Mobile Application Development (22617) Practical No. 16

public void onClick(View view) {


Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String time = "Current Time : " + sdf.format(c.getTime());
et2.setText(time);
}

});
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String date = "Current Date : " + sdf.format(c.getTime());
et1.setText(date);
}
});

}
}

//=================================================================
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/editTextDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

Maharashtra State Board of Technical Education 7


Mobile Application Development (22617) Practical No. 16

android:ems="12"
android:inputType="date"
android:layout_marginTop="50dp"
android:layout_marginLeft="10dp" />

<EditText
android:id="@+id/editTextTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="12"
android:inputType="time"
android:layout_below="@+id/editTextDate"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Date"
android:layout_toRightOf="@+id/editTextDate"
android:layout_marginTop="50dp"
android:layout_marginLeft="10dp" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Time"
android:layout_toRightOf="@+id/editTextTime"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/button1" />

Maharashtra State Board of Technical Education 8


Mobile Application Development (22617) Practical No. 16

</RelativeLayout>

XI. References / Suggestions for further Reading


1. https://www.tutorialspoint.com/android
2. https://stuff.mit.edu
3. https://www.tutorialspoint.com/android/android_advanced_tutorial.pdf
4. https://developer.android.com

XII. Assessment Scheme

Performance indicators Weightage

Process related (10 Marks) 30%

1. Logic Formation 10%


2. Debugging ability 15%
3. Follow ethical practices 5%
Product related (15 Marks) 70%

4. Interactive GUI 20%


5. Answer to Practical related questions 20%
6. Expected Output 20%
7. Timely Submission 10%
Total (25 Marks) 100%

List of student Team Members


1
2
3
4

Marks Obtained Dated signature of


Teacher
Process Product Total
Related(10) Related(15) (25)

Maharashtra State Board of Technical Education 9

You might also like