0% found this document useful (0 votes)
4 views3 pages

Scan 25 Mar 25 09 44 02

The document outlines the steps to create an Android application that implements a DatePicker feature. It includes modifications to the MainActivity.java file, XML layout components, and string resources. The final steps involve running the application on an Android device to verify its functionality.

Uploaded by

Ranjit Jadhav
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)
4 views3 pages

Scan 25 Mar 25 09 44 02

The document outlines the steps to create an Android application that implements a DatePicker feature. It includes modifications to the MainActivity.java file, XML layout components, and string resources. The final steps involve running the application on an Android device to verify its functionality.

Uploaded by

Ranjit Jadhav
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/ 3

Description

Steps
studio to create an Android
will use Android
You it as DatePicker under a
and name
pplication
th com.example.datepicker.
package file to add

Modify src/MainActivity.java
2
code.
necessary to add
the res/layout/activity_main
3 Modify
XML Components.
respective to add
the res/values/string.xml
4 Modify
string
components.
necessary
orted a running
and choose
uary 5 Run the application on it
the application
and install
android device

and verify the results.


main activity
of the modified
is the content
Following
d by
file src/com.example.datepicker/MainActivity.java.
uary

package com.example.datepicker;

Calendar;
importjava.util.
are
Jimport android.app.Activity;

import android.app.DatePickerDialog;
int

import android. app.Dialog:

import android.os.Bundle;

|import android.view.Menu:

import android.view. View;

import android. widget.DatePicker;

import android. widget. Text View;

import android.widget.Toast;

public class MainActivityextends Activity {


of
private DatePickerdatePicker;
er

private Calendar calendar;

private TextViewdateView;

private int year,month, day:

@Override

protected void
onCreate(Bundle
savedInstanceState)

super.onCreate(savedlnstanceState):

setContentView{R.lavout.actívity
main):
Mabile Application
Development (MSBTE Sem-6
Comp/|T) 4-45 View
ldate View =
(TextView) Designing User Interface with

findViewByld(R.id.textView3):
calendar= showDate(argl, arg2+1,
Calendar.getInstance(): arg3):

year =calendar.get(Calendar. YEAR):


month = calendar.get(Calendar. MONT):
day = private void showDate(int year, int month, int day)
calendar.get(Calendar.DAY OF MONTH):
dateView.seflext(new
showDate(year, month+1, day):
|StringBuilder).append(day).append")

append(month).appendC).append(year)):
@SuppressWamings("'deprecation")
public void setDate(View view){

showDialog(999);
Following is the modified content of the xml
Toast.makeText(getApplicationContext(), "'ca', res/layout/activity_main.xml.

Toast.LENGTH SHORT) |<?xml version="1.0" encoding="utf-8"?>

show); <RelativeLayout

} xmlns:android="http://schemas.android.com/apk/res/an
droid"
@Override
xmlns:tools ="htp://schemas.android.com/tools"
protected Dialog onCreateDialog(int id) {
android:layout width="match parent"
TODO Auto-generated mnethod stub

if (id =999) { android:layout height="match_ parent"

|android:paddingBottom="@dimen/activity_vertical ma
return new DatePickerDialog(this, rgin"

myDateListener, year, month, day);


android:paddingLeft="@dimen/activity_ horizontal mar
gin

return null: android:paddingRight="@dimen/activity_horizontal_m


argin"

android:paddingTop="@dimen/activity_ vertical_margin
private

|DatePickerDialog.OnDateSetListenermyDateListener = tools:context="MainActivity" >


|new
<Button
DatePickerDialog.OnDateSetListener() {
android:id="@+id/buttonl"
@Override
Jandroid:layout_width ='wrap_ content"
public void onDateSet(DatePicker arg0,
android:layout_height="wrap_content"
int argl, int arg2, int arg3) {
Jandroid:layout alignParentTop="true"
/TODO Auto-generated method stub
landrojd:layout_centerHorizontal='true"
l argl =year android:layout_marginTop="70dp"
l arg2 =month android:onClick='setDate"

larg3 = day
android:text="@string/date button_set"/>

TechKnowledge
PublCatinns
with
User Interface View
Designing
4-46
Comp/lT) selected"
Development (MSBTE Sem-6
Application
Motbile android:text="@string/date
"?android:attr/textAppearance

<TextView Jandroid:textAppearance=
textView)"
Mediun"/>
android:id="@+id
|</RelativeLayout> xroi
width='wrap content"
the res/values/string.
android:lavout
is the contentof
Following
android:lavout
height="wrap content"
encoding="utf-8"?>
android:layout_alignarentTop="ue"
<?ml version="l.0"
centerHorizontal=tne" <resources>
android:lavout
name"> DatePicker</string>
marginTop="2kdp" <string name="app
android:layout </stríng>
settings">Settings
date abel set"
name="action
android:text=@string <string >
world!</stríng
="?android:attr/textAppearance world"> Hello
android:textAppearance <string name="hello se
the button to
Medium> label set'Press
<string name"date
<Textliew
the date </string
>
Date </string
android:id="@+id textView2" button set">Set
<string name="date
width="wrap content" view set"> TheDate is:
android:layout
<string name="date
android:lavout height="wrap_content" </string >
>
below="@+id buttonl" selected'></string
android:lavout <string name="date

android:lavout marginTop="66dp" </resources>


1"
android:layout toLefiOf="@+id/button
Review Questions
view, set"
android:text="@string date

Ul by using following UI
android:textAppearance="?android:attr/textAppearance Q.1 Design a rich

Medium" Component.

<TextView Image button, toggle button


Text view, button,

android:id="@+id/textView3" UI
Q.2 Design a student registration form using

android:layout width="wrap content" Component.

Jandroid:layout height="wrap content"


Q.3 Demonstrate use of list view and gridview.

android:layout_ alignRight="@+id/buttonl"
Q.4 Explain signiticance of displaying Alert.
android:layout below="@+id/textView2"
Q.5 Develop application for date-time picker.
android:layout marginTop="72dp"

You might also like