0% found this document useful (0 votes)
48 views36 pages

Mobile APK Legacy Version Guide

The document contains multiple Android application examples demonstrating various layout implementations such as ConstraintLayout, LinearLayout, AbsoluteLayout, FrameLayout, RelativeLayout, and TableLayout. Each example includes the corresponding XML layout files and Java code for the MainActivity class, showcasing UI components like TextViews, EditTexts, Buttons, and CheckBoxes. The document is structured into practical exercises, each focusing on a specific aspect of Android UI development.

Uploaded by

Sakshi Kale
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)
48 views36 pages

Mobile APK Legacy Version Guide

The document contains multiple Android application examples demonstrating various layout implementations such as ConstraintLayout, LinearLayout, AbsoluteLayout, FrameLayout, RelativeLayout, and TableLayout. Each example includes the corresponding XML layout files and Java code for the MainActivity class, showcasing UI components like TextViews, EditTexts, Buttons, and CheckBoxes. The document is structured into practical exercises, each focusing on a specific aspect of Android UI development.

Uploaded by

Sakshi Kale
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

Practical 4

activity_main.xml

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


<[Link]
intLayoutxmlns:android="[Link]
[Link]/apk/res/android"
xmlns:app="[Link]
apk/res-auto"
xmlns:tools="[Link]
/tools" android:layout_width=
"match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>
</[Link]
aintLayout>

[Link]

package [Link];

import
[Link]
ity;

import [Link];

public class MainActivity extends


AppCompatActivity {

@Override
protected void onCreate(Bundle
savedInstanceState) {
[Link](savedInstanceState);

setContentView([Link].activity_main);
}
}
Practical 5
Develop a program to implement Linear Layout and Absolute layout

activity_main.xml(LinearLayout)

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


<LinearLayout android:layout_width="wrap_content"
xmlns:android="[Link]
om/apk/res/android" android:layout_height="wrap_content"
android:text="Mobile
xmlns:app="[Link] no.=9895645564" />
apk/res-auto"
<TextView
xmlns:tools="[Link] android:id="@+id/textView4"
/tools"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" android:layout_height="wrap_content"
tools:context=".MainActivity"> android:text="Name=Ankita" />
<TextView <TextView
android:id="@+id/textView3" android:id="@+id/textView1"

android:layout_width="wrap_content" android:layout_width="wrap_content"

android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Name=Komal" /> android:text="Age=25" />
<TextView
<TextView android:id="@+id/textView2"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Mobile
android:text="Age=20" /> no.=9898876564" />

<TextView </LinearLayout>
android:id="@+id/textView5"
[Link]

package [Link].pract_5linear;

import [Link];

import [Link];
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}

activity_main.xml(AbsoluteLayout)
android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
android:text="OK"
<AbsoluteLayout
android:layout_x="60px"
xmlns:android="[Link]
android:layout_y="600px"/>
om/apk/res/android"
<Button
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="match_parent">

android:layout_height="wrap_content"
<Button
android:text="Cancel"
android:layout_width="wrap_content"
android:layout_x="400px"
android:layout_y="600px"/>
</AbsoluteLayout>

AbsoluteLayout LinearLayout
Practical 6
Develop a program to implement Frame layout, relative layout and table layout.

activity_main.xml(TableLayout)

<?xml version="1.0" encoding="utf-8"?> android:layout_height="wrap_content"/>


<TableLayout
xmlns:android="[Link] </TableRow>
om/apk/res/android" <TableRow>
android:layout_width="fill_parent" <TextView
android:layout_height="fill_parent"> android:text="Last Name"
android:layout_height="wrap_content"
<TableRow android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> />
<TextView <EditText android:width="100px"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time"
/>
android:layout_height="wrap_content"/>
<TextClock
</TableRow>
android:layout_height="wrap_content"
<TableRow
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/textClock"
android:layout_height="fill_parent">
/>
<RatingBar
</TableRow>
<TableRow>
android:layout_height="wrap_content"
<TextView
android:text="First Name"
android:layout_width="wrap_content"
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
/>
</TableRow>
android:layout_height="wrap_content"
<TableRow
/>
android:layout_width="fill_parent"
<EditText
android:layout_height="fill_parent"/>
android:width="200px"
<TableRow
android:layout_width="fill_parent"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>
<Button android:layout_width="fill_parent"
android:layout_width="wrap_content" android:layout_height="fill_parent" />
android:layout_height="wrap_content" <TextView
android:text="Submit" android:layout_width="fill_parent"
android:id="@+id/button" android:layout_height="fill_parent"
/> android:text="Frame Demo"
android:textSize="30px"
</TableLayout> android:textStyle="bold"
android:gravity="center"/>
[Link]
</FrameLayout>
package [Link];
import
[Link]
ity;
import [Link];
public class MainActivity extends
AppCompatActivity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
[Link](savedInstanceState);

setContentView([Link].activity_main);
}
}

activity_main.xml(FrameLayout)

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


<FrameLayout
xmlns:android="[Link]
om/apk/res/android"

xmlns:app="[Link]
apk/res-auto"

xmlns:tools="[Link]
/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" TableLayout
tools:context=".MainActivity">

<ImageView

android:src="@drawable/ic_launcher_fore
ground"
android:scaleType="fitCenter"
Practical 7
Develop a program to implement Text View and Edit Text.

activity_main.xml

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


<TableLayout android:layout_height="wrap_content"
xmlns:android="[Link] android:gravity="center"
[Link]/apk/res/android" android:textSize="25dp"
xmlns:app="[Link] android:text="Login Page" />
m/apk/res-auto"
xmlns:tools="[Link]
<TableRow
om/tools"

android:layout_width="match_parent"
android:layout_width="match_parent"

android:layout_height="wrap_content"
android:layout_height="match_parent"
android:padding="50dp"
android:gravity="center_horizontal">
tools:context=".MainActivity">

<TextView
<TextView

android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1" android:id="@+id/btn1"
android:gravity="center"
android:text="Enter UserName:" android:layout_width="wrap_content"
/>
android:layout_height="wrap_content"

<EditText
android:layout_marginBottom="50dp"
android:id="@+id/user"
android:text="Login" />

android:layout_height="wrap_content"
android:layout_weight="1" </TableLayout>
android:hint="abc@[Link]"
/>

</TableRow>
<TableRow

android:layout_width="match_parent"

android:layout_height="wrap_content"
[Link]
android:gravity="center_horizontal">
package [Link];

<TextView import
[Link]
android:layout_height="wrap_content" ctivity;
android:layout_weight="10" import [Link];
android:gravity="center" public class MainActivity extends
android:text="Enter Password:" AppCompatActivity {
/> @Override

protected void onCreate(Bundle


<EditText savedInstanceState) {
android:id="@+id/pass"
[Link](savedInstanceState);
android:layout_height="wrap_content"
android:layout_weight="1" setContentView([Link].activity_main)
android:hint="1234" /> ;
}
}

</TableRow>

<Button
Practical 9

Develop a program to implement Button, Image Button and Toggle


Button.
activity_main.xml

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


8"?> android:src="@drawable/ic_launcher_
<RelativeLayout foreground"
xmlns:android="[Link] android:contentDescription="Image
[Link]/apk/res/android" Button"
android:layout_width="match_parent" android:layout_below="@id/button"
android:layout_height="match_parent" android:layout_centerHorizontal="true
> "
android:layout_marginTop="50dp"/>

<Button
android:id="@+id/button" <ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" android:layout_height="wrap_content"
android:textOn="On"
android:layout_centerHorizontal="true android:textOff="Off"
"
android:layout_below="@id/imageBut
android:layout_marginTop="100dp"/> ton"

android:layout_centerHorizontal="true
<ImageButton "
android:id="@+id/imageButton"
android:layout_marginTop="50dp"/>
android:layout_width="wrap_content"
</RelativeLayout>
android:layout_height="wrap_content"
[Link]
package [Link]; import [Link];
import [Link];
import import [Link];
[Link] import [Link];
Activity;
public class MainActivity extends
import [Link]; AppCompatActivity {
import [Link]; Button button;
ImageButton imageButton; Toast.LENGTH_SHORT).show();
ToggleButton toggleButton; }
@Override });
protected void onCreate(Bundle
savedInstanceState) {
[Link]
[Link](savedInstanceState); stener((buttonView, isChecked) -> {
if (isChecked) {
setContentView([Link].activity_mai
n);
button = [Link]([Link],
findViewById([Link]); "Toggle Button ON",
imageButton = Toast.LENGTH_SHORT).show();
findViewById([Link]); } else {
toggleButton =
findViewById([Link]); [Link]([Link],
[Link](new "Toggle Button OFF",
[Link]() { Toast.LENGTH_SHORT).show();
@Override }
public void onClick(View v) { });
}
[Link]([Link], }
"Button Clicked",
Practical 10
Develop a program to implement login window using above UI controls.
activity_main.xml

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


<TableLayout android:layout_width="wrap_content"
xmlns:android="[Link]
[Link]/apk/res/android" android:layout_height="wrap_content"
xmlns:app="[Link] android:gravity="center"
m/apk/res-auto" android:textSize="25dp"
xmlns:tools="[Link] android:text="Login Page" />
om/tools"

<TableRow
android:layout_width="match_parent"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="50dp"
android:layout_height="wrap_content"
tools:context=".MainActivity">

android:gravity="center_horizontal">
<TextView
android:layout_height="wrap_content"
<TextView android:layout_weight="10"
android:gravity="center"
android:layout_height="wrap_content" android:text="Enter Password:"
android:layout_weight="1" />
android:gravity="center"
android:text="Enter UserName:"
<EditText
/>
android:id="@+id/pass"

<EditText android:layout_height="wrap_content"
android:id="@+id/user" android:layout_weight="1"
android:hint="1234" />
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="abc@[Link]"
/> </TableRow>

</TableRow> <Button
<TableRow android:id="@+id/btn1"

android:layout_width="wrap_content"

android:layout_width="match_parent"
android:layout_height="wrap_content"

android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:text="Login" />
android:gravity="center_horizontal">

</TableLayout>
<TextView

[Link] protected void onCreate(Bundle


savedInstanceState) {
package [Link];
[Link](savedInstanceState);
import
[Link] setContentView([Link].activity_main)
ctivity; ;
import [Link]; }
public class MainActivity extends }
AppCompatActivity {
@Override
Practical 11
Develop a program to implement Checkbox.
[Link]
package [Link]; import [Link];
import [Link];
import import [Link];
[Link] import [Link];
ctivity;
public class MainActivity extends
AppCompatActivity { checked",Toast.LENGTH_SHORT).sho
CheckBox cb1,cb2,cb3,cb4,cb5; w();
@Override } else
protected void onCreate(Bundle
savedInstanceState) { {[Link]([Link],cb2.
getText().toString()+"
[Link](savedInstanceState); isunchecked",Toast.LENGTH_SHORT).
show();
setContentView([Link].activity_main) } } });
; [Link](new
cb1=findViewById([Link]); [Link]()
{ @Override public void
cb2=findViewById([Link].checkBox2); onClick(View view)
{ if ([Link]())
cb3=findViewById([Link].checkBox3); {

cb4=findViewById([Link].checkBox4); [Link]([Link], "",


Toast.LENGTH_SHORT).show();
cb5=findViewById([Link].checkBox5);
[Link](new [Link]([Link], "",
[Link]() Toast.LENGTH_SHORT).show();
{@Override public void
onClick(View view) [Link]([Link], "",
{if ([Link]()) Toast.LENGTH_SHORT).show();

{[Link]([Link],cb1. [Link]([Link],cb3.
getText().toString()+" getText().toString()+"
ischecked",Toast.LENGTH_SHORT).sh ischecked",Toast.LENGTH_SHORT).sh
ow(); ow();
} }else {
else {

[Link]([Link],cb1. [Link]([Link],cb3.
getText().toString()+" getText().toString()+"
isunchecked",Toast.LENGTH_SHORT). isunchecked",Toast.LENGTH_SHORT).
show(); show();
} } }); } } });
[Link](new [Link](new
[Link]() [Link]()
{@Override public void {@Override public void
onClick(View view) onClick(View view)
{ if ([Link]()) {if ([Link]()){
{
[Link]([Link],cb4.
[Link]([Link],cb2. getText().toString()+"
getText().toString()+"is ischecked",Toast.LENGTH_SHORT).sh
ow(); ([Link]()){ [Link](M
}else [Link],[Link]().toString()
+"
{[Link]([Link],cb4. ischecked",Toast.LENGTH_SHORT).sh
getText().toString()+" ow();
isunchecked",Toast.LENGTH_SHORT). }else{[Link](MainActivit
show(); [Link],[Link]().toString()+"
} } }); isunchecked",Toast.LENGTH_SHORT).
[Link](new show();
[Link]() } } });
{ @Override public void }
onClick(View view }
){if
activity_main.xml
app:layout_constraintTop_toTopOf="p
<?xml version="1.0" encoding="utf-8"?> arent"
<[Link]
straintLayout app:layout_constraintVertical_bias="0.
xmlns:android="[Link] 11" />
[Link]/apk/res/android" <CheckBox
android:id="@+id/checkBox"
xmlns:app="[Link]
m/apk/res-auto" android:layout_width="wrap_content"

xmlns:tools="[Link] android:layout_height="wrap_content"
om/tools" android:text="Java"

android:layout_width="match_parent" app:layout_constraintBottom_toBotto
mOf="parent"
android:layout_height="match_parent"
tools:context=".MainActivity"> app:layout_constraintEnd_toStartOf="
@+id/checkBox2"
<TextView
android:id="@+id/textView" app:layout_constraintHorizontal_bias="
android:layout_width="257dp" 0.645"
android:layout_height="33dp"
android:textAlignment="center" app:layout_constraintStart_toStartOf="
android:text="Select Language" parent"

app:layout_constraintBottom_toBotto app:layout_constraintTop_toBottomOf
mOf="parent" ="@+id/textView"

app:layout_constraintEnd_toEndOf="pa app:layout_constraintVertical_bias="0.
rent" 069" />
<CheckBox
app:layout_constraintStart_toStartOf=" android:id="@+id/checkBox2"
parent"
app:layout_constraintVertical_bias="0.
android:layout_width="wrap_content" 215" />
<CheckBox
android:layout_height="wrap_content" android:id="@+id/checkBox4"
android:text="Python"
android:layout_width="wrap_content"
app:layout_constraintBottom_toBotto
mOf="parent" android:layout_height="wrap_content"
android:text="C"
app:layout_constraintEnd_toEndOf="pa
rent" app:layout_constraintBottom_toBotto
mOf="parent"
app:layout_constraintHorizontal_bias="
0.655" app:layout_constraintEnd_toEndOf="pa
rent"
app:layout_constraintStart_toStartOf="
parent" app:layout_constraintHorizontal_bias="
0.591"
app:layout_constraintTop_toBottomOf
="@+id/textView" app:layout_constraintStart_toStartOf="
parent"
app:layout_constraintVertical_bias="0.
069" /> app:layout_constraintTop_toBottomOf
<CheckBox ="@+id/textView"
android:id="@+id/checkBox3"
app:layout_constraintVertical_bias="0.
android:layout_width="wrap_content" 215" />
<CheckBox
android:layout_height="wrap_content" android:id="@+id/checkBox5"
android:text=".Net"
android:layout_width="wrap_content"
app:layout_constraintBottom_toBotto
mOf="parent" android:layout_height="wrap_content"
android:text="Html"
app:layout_constraintEnd_toEndOf="pa
rent" app:layout_constraintBottom_toBotto
mOf="parent"
app:layout_constraintHorizontal_bias="
0.286" app:layout_constraintEnd_toEndOf="pa
rent"
app:layout_constraintStart_toStartOf="
parent" app:layout_constraintHorizontal_bias="
0.468"
app:layout_constraintTop_toBottomOf
="@+id/textView" app:layout_constraintStart_toStartOf="
parent"
app:layout_constraintTop_toBottomOf
="@+id/textView"

app:layout_constraintVertical_bias="0.
348" />
</[Link]
nstraintLayout>
Practical 12
Develop a program to implement Radio Button and Radio Group.
[Link]
package [Link]; findViewById([Link]);
import radio1 = findViewById([Link].radio1);
[Link] radio2 = findViewById([Link].radio2);
ctivity; radioMale =
import [Link]; findViewById([Link]);
import [Link]; radioFemale =
import [Link]; findViewById([Link]);
import [Link]; radioGroup =
import [Link]; findViewById([Link]);
public class MainActivity extends }
AppCompatActivity { public void showSelected (View
RadioButton radio1, radio2, view)
radioMale, radioFemale; {String selected ="Selected radio
RadioGroup radioGroup; buttons:\n";
@Override if ([Link]())selected
protected void onCreate(Bundle +="Radio Button 1\n";
savedInstanceState) { if ([Link]())selected
+="Radio Button 2\n";
[Link](savedInstanceState); RadioButton selectedRadio =
findViewById([Link]
setContentView([Link].activity_main) adioButtonId());
; selected +=
radio1 = findViewById([Link].radio1); [Link]().toString();
radio2 = findViewById([Link].radio2); [Link]([Link],
radioMale = selected,
findViewById([Link]); Toast.LENGTH_SHORT).show();
radioFemale = }
findViewById([Link]); }
radioGroup =
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?> android:layout_width="match_parent"
<LinearLayout xmlns:android
="[Link] android:layout_height="match_parent"
s/android" android:orientation="vertical"
android:padding="20dp"
xmlns:app="[Link] tools:context=".MainActivity">
m/apk/res-auto" <TextView
android:layout_width="match_parent"
xmlns:tools="[Link] android:layout_height="wrap_content"
om/tools" android:gravity="center"
android:text="Single Radio Button"
android:textSize="20sp" /> <RadioGroup
<RadioButton android:id android:id ="@+id/radioGroup"
="@+id/radio1"
android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content" <RadioButton
android:text="Radio Button 1" android:id ="@+id/radioMale"
android:textSize="18dp"
android:textStyle="bold"/> android:layout_width="wrap_content"
<RadioButton android:id
="@+id/radio2" android:layout_height="wrap_content"
android:text="Male"
android:layout_width="match_parent" android:textSize="18dp"
android:textStyle="bold" />
android:layout_height="wrap_content" <RadioButton
android:text="Radio Button 2" android:id ="@+id/radioFemale"
android:textSize="18dp"
android:textStyle="bold" /> android:layout_width="wrap_content"
<View
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="2dp" android:text="Female"
android:background android:textSize="18dp"
="@android:color/black" android:textStyle="bold" />
android:layout_marginTop="20dp" </RadioGroup>
<Button
android:layout_marginBottom="20dp"/ android:id ="@+id/button"
>
<TextView android:layout_width="wrap_content"
android:id ="@+id/textView"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center_horizon
android:layout_height="wrap_content" tal"
android:gravity="center" android:text="Show Selected"
android:text="Radio button inside android:onClick ="showSelected"/>
RadioGroup" </LinearLayout>
android:textSize="20sp" />
Practical 13
Develop a program to implement Progress Bar.

[Link]

public class MainActivity extends progressDialog = new


AppCompatActivity { Button btn; ProgressDialog([Link])
ProgressBar pgr; ; [Link]("File
ProgressDialog progressDialog; downloading....");
@Override [Link](P
protected void onCreate(Bundle rogressDialog.STYLE_HORIZONTAL);
savedInstanceState) { [Link](fals
[Link](savedInstanceState e); [Link]();
); [Link](40);
setContentView([Link].activity_ }
main); });
btn=findViewById([Link]); }}
[Link](new
[Link]() {
@Override
public void onClick(View view) {

Activity_main.xml
<?xml version="1.0" encoding="UTF- <ProgressBar
8"?> android:id="@+id/progressBar"
<RelativeLayout
xmlns:android="[Link] style="?android:attr/progressBarStyleH
[Link]/apk/res/android" orizontal"
android:layout_width="200dp"
xmlns:app="[Link] android:layout_height="200dp"
m/apk/res-auto"
android:layout_centerInParent="true"
xmlns:tools="[Link] android:indeterminate="false"
om/tools" android:max="100"
android:progress="65" />
android:layout_width="match_parent"

</RelativeLayout>
android:layout_height="match_parent"
tools:context=".MainActivity">
Practical 14

Develop a program to implement List View, Grid View, Image


View and Scroll View.

Activity_main.xml(ImageView)
<RelativeLayout
xmlns:android="[Link] android:layout_width="match_parent"
[Link]/apk/res/android" android:layout_height="400dp" />
<Button
xmlns:app="[Link]
om/apk/res-auto" android:layout_width="match_parent"
android:layout_height="70dp"
xmlns:tools="[Link]
com/tools" android:layout_below="@id/imagev"

android:layout_width="match_parent" android:layout_marginTop="110dp"
android:text="Change Image"
android:layout_height="match_parent" android:id="@+id/btn"/>
tools:context=".MainActivity" </RelativeLayout>
android:padding="40dp">
<ImageView
android:id="@+id/imagev"

[Link]
package [Link]; import
[Link]
ctivity; =findViewById([Link]);
btn=findViewById([Link]);
import [Link];
import [Link]; [Link]([Link].
import [Link]; smiley);
import [Link]; [Link](new
[Link]()
public class MainActivity extends {
AppCompatActivity { @Override public void
ImageView imagev; onClick(View view) { if(a==0)
Button btn; int a= 0;
@Override { [Link]([Link]
protected void onCreate(Bundle [Link]); a=1;
savedInstanceState) { }
else{ [Link]([Link]
[Link](savedInstanceState); [Link]);
a=0; } } }); } }

setContentView([Link].activity_main)
;

imagev
ImageView
Activity_main.xml(ListView)
<?xml version="1.0" encoding="utf-8"?> android:layout_height="match_parent"
<RelativeLayout tools:context=".MainActivity">
xmlns:android="[Link] <ListView
[Link]/apk/res/android" android:padding="40dp"

xmlns:app="[Link] android:layout_width="match_parent"
m/apk/res-auto"
android:layout_height="match_parent"
xmlns:tools="[Link] android:id="@+id/Listview"/>
om/tools"

android:layout_width="match_parent" </RelativeLayout>

[Link]
package [Link]; [Link]
ctivity;
import
import [Link];
import [Link]; listView=findViewById([Link]);
import [Link]; ArrayAdapter<String> arr;
import [Link]; arr = new
import [Link]; ArrayAdapter<String>(this,
import [Link]; [Link].support_
import [Link]; simple_spinner_dropdown_item,
Subjectname);
public class MainActivity extends [Link](arr);
AppCompatActivity {
ListView listView; [Link](new
[Link]() {
private String @Override
Subjectname[]={"Android","java","php"," public void
hadoop","sap","python","ajax","cpp","Ru onItemClick(AdapterView<?> arg0,
by","Rails"}; View arg1, int position, long arg3) {
@Override
protected void onCreate(Bundle [Link]([Link],
savedInstanceState) { "Subject Name :" +
((TextView)arg1).getText().toString(),
[Link](savedInstanceState); Toast.LENGTH_SHORT).show();
}
setContentView([Link].activity_main) });
; }}
Activity_main.xml(ScrollView)
<RelativeLayout Android offers a unified
xmlns:android="[Link] approach to application
[Link]/apk/res/android" development for mobile
devices which means developers
xmlns:tools="[Link] need only develop for
om/tools" Android, and their applications
android:layout_width="fill_parent" should be able to run on
different devices powered by
android:layout_height="match_parent" Android. The first beta
tools:context=".MainActivity" version of the Android Software
android:id="@+id/linear1"> Development Kit (SDK)
<ScrollView was
android:layout_width="fill_parent" released by Google
android:layout_height="fill_parent" in 2007 where as the first commercial
android:scrollbars="horizontal"> version, Android 1.0, was
<LinearLayout released in September 2008. On June
27, 2012, at the Google I/O
android:layout_width="fill_parent" conference, Google announced the
next Android version, 4.1 Jelly Bean.
android:layout_height="fill_parent" Jelly Bean is an incremental update,
android:layout_margin="20dp"> with the primary aim of improving
<TextView the user interface, both in terms of
android:layout_width="match_parent" functionality and performance.
The source code for Android is
android:layout_height="match_parent" available under free and open source
android:text="Android is an software licenses. Google publishes
open source and Linux-based most of the code under the Apache
Operating System for mobile License version 2.0 and the rest,
devices such as smartphones Linux kernel changed."
and tablet computers. android:textSize="20sp"/>
Android was developed by the Open </LinearLayout>
Handset Alliance, led by </ScrollView>
Google, and other companies. </RelativeLayout>
Practical 15
Develop a program to implement Custom Toast Alert
Activity_main.xml
Practical 16
Develop a program to implement Date and Time Picker.

[Link]
package button
[Link];
[Link](n
import ew [Link]() {
[Link] @Override
ctivity; public void onClick(View v) {
showDatePicker();
import [Link]; }
import [Link]; });
import [Link];
import [Link]; [Link](
import [Link]; new [Link]() {
import [Link]; @Override
import [Link]; public void onClick(View v) {
showTimePicker();
public class MainActivity extends }
AppCompatActivity { });
Button buttonDatePicker, }
buttonTimePicker; private void showDatePicker() {
TextView textViewDate,
textViewTime; Calendar calendar =
@Override [Link]();
protected void onCreate(Bundle int year =
savedInstanceState) { [Link]([Link]);
int month =
[Link](savedInstanceState); [Link]([Link]);
int dayOfMonth =
setContentView([Link].activity_main) [Link](Calendar.DAY_OF_MONT
; H);
buttonDatePicker = DatePickerDialog
findViewById([Link].button_date_picker); datePickerDialog = new
buttonTimePicker = DatePickerDialog([Link],
findViewById([Link].button_time_picker); (view, year1, monthOfYear,
textViewDate = dayOfMonth1) -> {
findViewById([Link].text_view_date); String selectedDate =
textViewTime = "Selected Date: " + (monthOfYear + 1)
findViewById([Link].text_view_time); + "/" + dayOfMonth1 + "/" + year1;

// Set listener for the Date Picker [Link](selectedDate);


}, year, month, dayOfMonth); {
[Link](); // Update the TextView
} with the selected time
private void showTimePicker() { String selectedTime =
Calendar calendar = "Selected Time: " + hourOfDay + ":" +
[Link](); (minute1 < 10 ? "0" + minute1 :
int hour = minute1);
[Link](Calendar.HOUR_OF_DAY);
int minute = [Link](selectedTime);
[Link]([Link]); }, hour, minute, true);
TimePickerDialog [Link]();
timePickerDialog = new }
TimePickerDialog([Link], }
(view, hourOfDay, minute1) ->
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?> android:textSize="16sp"
<LinearLayout
xmlns:android="[Link] android:layout_marginTop="10dp"/>
[Link]/apk/res/android"

android:layout_width="match_parent" <Button

android:layout_height="match_parent" android:id="@+id/button_time_picker"
android:orientation="vertical"
android:padding="20dp"> android:layout_width="wrap_content"

android:layout_height="wrap_content"
<Button android:text="Pick a Time"
android:layout_marginTop="20dp"
android:id="@+id/button_date_picker" />

android:layout_width="wrap_content"
<TextView
android:layout_height="wrap_content" android:id="@+id/text_view_time"
android:text="Pick a Date" />
android:layout_width="wrap_content"

<TextView android:layout_height="wrap_content"
android:id="@+id/text_view_date" android:text="Selected Time: "
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"/>
android:layout_height="wrap_content" </LinearLayout>
android:text="Selected Date: "
Practical 17
Develop a program to create an activity.

[Link]
package [Link]; invoked");

import [Link]([Link],"Star
[Link] t",Toast.LENGTH_SHORT).show(); }
ctivity; @Override protected void onResume()
import [Link]; { [Link]();
import [Link]; Log.d("Activity_Lifecycle","onResume
import [Link]; invoked");
import [Link];
import [Link]; [Link]([Link],"Res
ume",Toast.LENGTH_SHORT).show(); }
public class MainActivity extends @Override protected void onPause()
AppCompatActivity { { [Link]();
Log.d("Activity_Lifecycle","onPause
@Override invoked");
protected void onCreate(Bundle [Link]([Link],"Pau
savedInstanceState) { se",Toast.LENGTH_SHORT).show(); }
@Override protected void onStop()
[Link](savedInstanceState); { [Link]();
Log.d("Activity_Lifecycle","onStop
setContentView([Link].activity_main) invoked");
; [Link]([Link],"Sto
p",Toast.LENGTH_SHORT).show(); }
Log.d("Activity_Lifecycle","onCreate @Override protected void onRestart()
invoked"); { [Link]();
Log.d("Activity_Lifecycle","onRestart
[Link]([Link],"Cre invoked");
ated",Toast.LENGTH_SHORT).show(); [Link]([Link],"Res
} @Override protected void onStart() tart",Toast.LENGTH_SHORT).show(); }
{ [Link](); @Override protected void onDestroy()
Log.d("Activity_Lifecycle","onStart { [Link]();
Log.d("Activity_Lifecycle","onDestroy troy",Toast.LENGTH_SHORT).show();
invoked"); }
}
[Link]([Link],"Des

Activity_main.xml
<?xml version="1.0" encoding="utf- android:layout_width="wrap_content"
8"?>
<RelativeLayout android:layout_height="wrap_content"
xmlns:android="[Link] android:text="Activity Life Cycle"
[Link]/apk/res/android" android:textColor="#000000"
android:textSize="25dp"
xmlns:tools="[Link] android:gravity="center"
com/tools" android:textStyle="bold"
android:id="@+id/activity_main"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_centerHorizontal="true
android:layout_height="match_parent" "/>
tools:context=".MainActivity"> </RelativeLayout>
<TextView
Practical 18
Develop a program to implement new activity using explicit intent and
implicit intent.

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_marginTop="150dp"
xmlns:android="[Link] android:layout_marginLeft="35dp"
[Link]/apk/res/android"
android:layout_marginRight="35dp"
xmlns:tools="[Link] android:paddingLeft="20dp"
om/tools"
android:id="@+id/activity_main" android:background="@drawable/ic_la
uncher_background" />
android:layout_width="match_parent" <Button
android:layout_width="150dp"
android:layout_height="match_parent"
tools:context=".MainActivity" android:layout_height="wrap_content"
android:orientation="vertical" > android:id="@+id/searchbutton"
<EditText android:text="SEARCH"
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="50dp" android:layout_below="@+id/enteredte
android:hint="Search here" xt"
android:id="@+id/enteredtext" android:layout_gravity="center" />
android:textColor="@color/black" </LinearLayout>

[Link]
package [Link];
import
import [Link];
[Link] import [Link];
ctivity; import [Link];
import [Link]; findViewById([Link]);
import [Link];
import [Link]; [Link](ne
import [Link]; w [Link](){
import [Link]; @Override public void
onClick(View v) { String etxt =
[Link]().toString();
public class MainActivity extends if(![Link]())
AppCompatActivity { { Intent intent = new
private Button mSearchButton; Intent(Intent.ACTION_WEB_SEARCH);
private EditText mEnterText; [Link]([Link],
@SuppressLint("MissingInflatedId") etxt);
@Override startActivity(intent); }
protected void onCreate(Bundle else
savedInstanceState) { { [Link]([Link],"N
ot entered anything",
[Link](savedInstanceState); Toast.LENGTH_LONG).show(); } } });
}
setContentView([Link].activity_main) }
;

mSearchButton = (Button)
findViewById([Link]);
mEnterText = (EditText)

You might also like