You are on page 1of 10

1813 Chavan Meet Dinesh

Outputs:

Aneotd emulator •
Android • Andro.d • 7T
2.36
listvieweg Practicall 4img Practica114img

CHANGE IMAGE CHANGE IMAGE

Andro,d Emulator - Android Emulator - Android Emu'atot - 5554


2:38 2:39

Practicall 4grid Practicall 4scroll Practicall 4scroll

4)
Hello World 7
Hello World 1

Hello World 8
10 11 12 Hello World 2
13 14 15
Hello World 9
Hello World 3

Hello World 10
Hello World 4
0 Hello World 11
Hello World 5

Hello World 12
ello World 6

Hello World 13
Hello World 7

Hello World 14
Helto World 8

Hello World 15
Mobile Application Developnwnt (226 17)

Following is the exatnple to create a toast.


Toast toast
"This is a message displayed in a Toast",
Toast.LENGT11 SHORT); toast.show();

The Toast.makeText()method is a factory method which creates a Toast object. The


method takes 3 parameters. First the methods needs a Context object which is obtained
by calling getApplicationContext().Note: The getApplicationContext() method is a
method that exists inside activities, so the above code has to be located in
an Activity subclass towork.
The second parameter is the text to be displayed In the Toast. The third parameter is
the time duration the Toast is to be displayed.

VIll. Resources required (Additional)

Sr. Instrument Specification Quantity Remar ks


No. /Object
Android enabled 2 GB RAM Data cable is
smartphone / Android mandatory for
version supporting emulator emulators

IX. Practical related Questions


Note: Below given are few sample questionsfor reference. Teachers must
design more such questions to ensure the achievement of identified CO.
1. List all predefined constants to specify the overall positioning of the Toast. Which
method is used to change the positioning of a Toast message on the screen?
2. List two constants of Toastclass.

(Space for answers)

(WID.*2. usQA.
o.ve.x.azki .
.i.s usa CA-Q
oc A. O..TOas4 rnssa.,e
oc Class. .inc-ud:es

2.t..Q1ßÄ/L
3:..GßfWL.g.m.CEtJ..T.æH4.P4.Zo.eUn.ld
4.1..Qteeruug.Ä.cA.1.Tee.-.v.eßT.1cAv
GlßfrJ$.T..%..- END.

Maharashtra State Board of Technical Education 77


R ICQ}RJ

cl.nss
cXmsS... GRY.Q„

X. Exercise
(Use blank space provide for answers or attachedmore pages if needed)
1. Write a program to display following toast message.

Toast Example
Hello World.Toast Example
Show Toast

Message for you:


You have got mail!

2. Write a program to display three checkboxesand one button named "Order "as
shown below. Once you click on button it should toast different selected
checkboxes along with items individual and total price.

Education
Maharashtra State Board of Technical 78
1813 Chavan Mcct I)incgh

•itca Program to display following toast message

tica/ Scustom - MainActivity (Pr.ctica'15custom •pp myrtl

java meet e U.•nActivity


7

pack»qe co•.eeet.practicaV15cvsto•,•

import

public class mainActivity extendsAppCo•patActivity(

protected void onCreate(BundtesavedInstanceState) (


super . onCreate (savedInstanceState) ;
setContentView(R. layout . activi ty_noin) ;
Button button findView8yId(R.id.button);
button.setOnCtickListener(new Vlew.0nCticktistpner()

public void onCIick(View v) (


Toast toast = newToast( contextMainActivity. this) ;
Layoutlnflater inflater getLayoutInf1ater();
Viewlayout - inflater. findViewById (R. id. custoa_ toast_root)) ;
toast. setView(1ayout) ;
toast. show() ;

Profiler Event Log Layout Inspector


Terrrunal Logcat App Inspection Budd
Control Run TODO O Problems 4soaces g
32:1 IF UTF-8
wnch succeeded (3 m.nutesago)

Android Emulator -
11:33
11:32

Practicall 5custom
Practicall 5custom
Hello Word. Toast
Examp:e
SHOW TOAST
SHOWTOAST

O o

Message for you:


You have got mail!
1813 Chavan M
cet l)
1. Write a Program to display following toast message

Practicall Scustom —activity_main.xml (Practicall 5custom.app.main)


res layout activity_main -e
Androtd activity_mam xrni budd gradie (•app) custom_toast. xrnl
MainActivity.java

manifests Code
SPIR
java version:" 1.0"
7' com meetoractica115custom <LinearLayout xnlns:android="http://schemas.android.com/apk/res/andro
MainActivtty android:
com meet, practica115custom android : layout_height- "natch_parent 'i
com meet.practicat15custom android :
lava ;generated' android:orientation:

drawable <TextView
layout "wrap_content"
android :
acttvtty_main.xml "wrap_content"
android :
custom_toast.xml
android: World, Toast Example"
mtpmap
Y values
<Button
(generated) android:
Gradle Scnpts android: "wrap_content"
build.gradle (Pt0'ect: PracticallS android :
butld.gradle (Module. Practica115 android: text:" Show
gradle-wrapper.properues (Grad
proguard-rules.pro (ProGuardRu </LinearLayout>
gradie.properties (Project Proper
LinearLayout
p Verston Control Run TODO O Problems Terminal Logcat App Inspection Build Profiler Event Log Layo•t
c Launch succeeded (a mnute ago) 271 LF ur;-e 4

Practica115custom —custom_toast.xml [Practicall 5custom.app.main)


ctica115custom app src main res layout custom_toast.xml Pixel6 AP127
activity_rnanxml MamActivity.java build gradle (•.app) custom_toast.xml

ECode EISplit
version:" 1.0"
<androidx. cardview. widget. CardView
xm1ns : android="http : //schemas.android.com/apk/res/android"
android : i'
android :
android : 12Cdp"
xntns : app: "http : //schemas.android.com/apk/res-auto"
android: "2Gdp"
app :
android :
<LinearLayout
android : "match_parent"
android :
"
android :
android : orientation: J' vert
<.TextView
android: "match_parent"
android: "wrap_content 'i
for you:'
android :
android :
<TextV iew
android :
android :
android: text:" You have got nail!"
android : textSize= "18dp "
android : "

</androidx. cardview.widget. CardView>


Lap.' "
Log
VersionControl Run TODO O Prouems Terrninal Logcat App Inspection Build Profiler C) Event
1813 -- Chavan Mcct I)inesh
2. Write a Program to display three checkboxes and show total selected toast message.

Practical'btoast —activity_main.xmt (Practtca'15toast.app main)


&.cticaltStoast app main res layout activity_main.xml Pixel6 API 27

MainActivity.iava build gradle app)

*Split
version: "1.0" encoding- nut
<LinearLayout xmtns:android="http://schemas.android.com/apk/res/android"
android : layout_width: "match _ parent "
andro id : " match_parent"
android: gravity: "center"
android : orientation: nvertical ">
<CheckBox
android : id/checkBox"
android : "wrap_content"
android : layout _height: "wrap_content"
android :

<CheckBox
android :
android: "wrap_content"
android :
android: " 20dp"
android : text:" Coffee"
<CheckBox
android : 0@+id/checkBox3"
android:
android :
android :
android:
<Button
android : "wrap_content
android :
android :
android.
android : 100dp"

Practicall 5toast —activity_main. xml [Practica115toast.app.mainl

ctica115toast app src main res layout activity_main.xml app Pixel 6 27

activity_mainxrnl MainActivity.java build.gradle (;app)


Code Split Z Design
Pixel 33 v
2 Palette activity_main.xmlv

Common TextView cunnamed>


Button
ImageView
Buttons Declared Attributes
= Recycler...
Widgets Fragmen... Layout
Layouts ScrollView layout_width match_parent
Containers •e Switch
layout_helght match_parent
visibility
visibility

Transforms

Vüew

V VersionControl Run TODO O Problems Terminal Logcat App inspection Build Profiler Event Log Layout inspector
Launch succeeded (3 minutes ago) 4 spaces
1813 Chavan Mcct I)incsh
Write a Program to display three checkboxes and show total selected toa.stmessage.

ApoCoeatActivitv (

cpp
Cyea' e(Bundle savedInstanceState) (

setCont entVie.(R . layout . v i ty_nnin) ;


eutton button
CheckBos c t id.check80x);
CheckBoy c?
Check80x c3 findVxevById(R.id . check80x3);
button.setOnCtickListener(

public void onCIick(Vie• v) (


String content
int total e;

. qetText IOORs\n";

contente=c2. getText ()+"

if(c3.
contente=c3.

ctal : *total;

Toast -makeText( context HainActivity. this, text- "Selected Items .• +content , Toast. LENGTH_LONG). show() ;

Terrrunal Logcat App inspection •S Build Profiler Layout Inspector


V C.c»trol Run 1000 O Problems
43:1 LF IJTF-8 4 spaces
Lanch succeeded (3 moutes

1147 11:48

Practicall 5toast Practicall Stoast


Stout

mzza

Coffee

ORDER ORDER

Coffe •S(m
ZORS
Total
(Space for an€"cr«)

CC-D oc

..y eAuyos ARS ...is..in... 2(1. ..N


:aQ.u2

elks.

CAFQ-o.V..

seÅQ-cleÅ

+43.

Maharashtra State Board of Technical Education 84


0 1 e pp Ica Ion eve onmen

1813 -- Chavan Meet Dinesh

l. Write a program to display following output. Use TimePicker with Spinner Mode.

[Practica116TimePicker.app.mainl
Practica116TimePicker—activity_main.xml
app Ptxel 6 API 27
Practicall6TimePicker app main res layout activity_mam.xml

Android activity_main xrnl MaynActivity.java


code split Design

manifests version-"1.0"
java <LinearLayout xnlns:android="http://schemas.android.com/apk/res/android"
com.meet.practica116timepick
android:
C MainActivtty
android :orientation: "vert icat"
com.meet.practica116timeptck
com.meet.practica116timepick android : layout _height:" match_parent
java
> res <TimePicker
res android:id="@+id/timePicker"
Gradie Scripts android
build.gradle (Project. Practtcai16 android.
build.gradle (t.'od'J!c: Practicat16 android.• "wrap_content"
gradle-wrapper.properties (Grad <TimePicker
proguard-rules.pro(ProGuardRu
android :
gradle.propertles (Project Proper
android
settings.gradle (Pro:ect Settings)
local-properties (SDK Location) android : timePickerMode= spinner"
android. • "wrap_content "
<TimePicker

android.•Layout_width:" match_pare t"


android: timePickerMode= 0c10ck 0
android: wrap_content"
</LinearLayout>

Build Profiler C) Event Log Layout Inspector


Run TOOO O Problems Terminal Logcat App Inspection
p VerstonControl 4 spaces
24:1 LF
Launch succeeded (a rrunuteago)

Practica116TimePicker —MainActivity.java [Practica116TimePicker.app.mainJ


OnTimeChangedListener onTimeChanged app Pixe16AP127• c: (t
MainActivity m onCreate anonymous

activtty_main xml MainActivity.java

package com.meet.practicat16timepicker;

import .

public class HainActivity extends AppCompatActivity

(é(lverrlde
{
protected void onCreate(BundtesavedInstanceState)
super. onCreate(savedInstanceState) ;
setContentView(R.layout. activity_main) ;
timePicker) ;
TimePicker timePicker findV iewById(R.id.
timePicker. setls24HourView(true) ;
TimePicker.0nTineChangedListener()
timePicker. setOnTimeChangedListener( new

(dOverride
view, int hourOfDay,int minute) (
public void onTimeChanqed(TinePicker
int hours hourOfDay;
String

hour hourOfOay -12;

Toast .makerext( context'HainActivity. this, text: "Selected Time is: "*hour." Toast . LENGTH.SHORT). show() ;

C) Eventcog inspector
Run 1000 O proNems Termjnal E Logcat App inspection Build t". Profiler
p Versm Contre UTE-8 4 spaces
3884
Launch succeeded (2 muuÄesago)
1813 —Chavan Meet I)inesh

Write a program to display following output. Use 'limelhckcr with Spinncr Mode.

• mainl

t . set se) ;

void view. int hourOfOay,int ninute) (


toast .•ogeText( BainActivity.this, •selected Tine is: " *hourOfDap- . ••minute, Toast . LENGTH_SHOPT)
. Sho.();

Ti•ePicker tinePicker2 : findViewById(R.id.tinePicker2);


t feePicker2. setl false) ;
ti•ePicker2.setOnT imeChanqedListener(qeo . Onr %methanqeäl-istoner() (

view, int hourOfOay,int minute) (


public void onTineChanged(TimePicker
Toast .nokeText( mainActivity. this, "Selected Time is: "+hourOfOaye". " •minute, Toast. LENGTH_SHORT)
. show();

V TOOO O Prouems Terrt€nal App Inspection Build Profiler Event Log Layt*lt
(2 tngunes ago) 56•.1LF UTF-g asoaces

12:26 12:27

Practicall 6TimePicker Practicall 6TimePicker

12 26 14 28

12 26 12 27

11 11

10 10

Selected Time is: 2.28PM

You might also like