Android
Android
GEORGE’S COLLEGE
ARUVITHURA
Course/Subject: ………………………………………………
Semester: …………………………………………………….
Certified that this is a bonafide record of practical work done by
Name: ………………………………………………………….
Reg. No.: ………………….…...................................................
Class: …………………… Batch: ……………………..........
Roll No.: ……………..…… Year: …………………………..
1
PROGRAM 1
AIM
PROGRAM
<androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView
android:id="@+id/txt"
android:layout_width="85dp"
android:layout_height="51dp"
android:text="Hello"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/sub"
2
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.454"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.313" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.clickme;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;
import android.view.View;
TextView txt;
Button sub;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sub=(Button)findViewById(R.id.sub);
3
txt=findViewById(R.id.txt);
sub.setOnClickListener(new View.OnClickListener() {
@Override
txt.setText("Text Changed");
});
OUTPUT
4
PROGRAM 2
AIM
PROGRAM
<androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView
android:id="@+id/txt"
android:layout_width="169dp"
android:layout_height="34dp"
android:text="Hello"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.702"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.139" />
5
<Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.542"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.284" />
<Button
android:id="@+id/upd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
6
package com.example.twobutton;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;
import android.view.View;
TextView txt;
Button sub;
Button upd;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = findViewById(R.id.txt);
sub.setOnClickListener(new View.OnClickListener() {
@Override
txt.setText("android");
});
upd.setOnClickListener(new View.OnClickListener() {
@Override
7
txt.setText("Java");
});
OUTPUT
8
PROGRAM 3
AIM
Read input from EditTextBox and display in text view on button click.
PROGRAM
<androidx.constraintlayout.widget.ConstraintLayout
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/nam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.736"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.291" />
9
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Text"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.104"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.294" />
<Button
android:id="@+id/change"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="change"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.392" />
<TextView
10
android:id="@+id/tx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.inputtextdisplay;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;
import android.view.*;
EditText nam;
TextView t;
Button change;
String a;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nam=(EditText) findViewById(R.id.nam);
t=(TextView)findViewById(R.id.tx) ;
11
change=(Button)findViewById(R.id.change);
change.setOnClickListener(new View.OnClickListener() {
@Override
a = (nam.getText().toString());
t.setText(a);
});
OUTPUT
12
PROGRAM 4
AIM
PROGRAM
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/usrnam"
android:layout_width="179dp"
android:layout_height="36dp"
android:text="User name"
android:textSize="24sp" />
/>
<EditText
android:id="@+id/nam"
13
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<TextView
android:id="@+id/pswrd"
android:layout_width="139dp"
android:layout_height="wrap_content"
android:layout_below="@+id/usrnam"
android:text="Password"
android:textSize="24sp" />
<EditText
android:id="@+id/psswrd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/nam"
android:ems="10"
android:inputType="textPersonName"
android:text="password" />
<Button
android:id="@+id/login"
14
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN" />
</LinearLayout>
</LinearLayout>
OUTPUT
15
PROGRAM 5
AIM
Create a screen that has input boxes for username, password, address, gender (radio buttons for male
and female), age (numeric), date of birth (DatePicker), state (Spinner) and a submit button. On
clicking the submit button, print all the data below the submit button (use any layout).
PROGRAM
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp">
<EditText
android:id="@+id/firstname_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="firstname"/>
<EditText
android:id="@+id/lastname_edittext"
16
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="lastname"/>
<EditText
android:id="@+id/email_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:inputType="textEmailAddress"
android:hint="email"/>
<EditText
android:id="@+id/password_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:inputType="textPassword"
android:hint="password"/>
<EditText
android:id="@+id/password_again_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
17
android:layout_marginTop="20dp"
android:inputType="textPassword"
android:hint="password_again"/>
<EditText
android:id="@+id/birthday_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:layout_marginTop="20dp"
android:hint="birthday"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="gender"/>
<RadioGroup
18
android:id="@+id/gender_radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="male"/>
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="female"/>
</RadioGroup>
</LinearLayout>
<Button
android:id="@+id/register_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
19
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="register"/>
<TextView
android:id="@+id/text_display"
android:layout_width="370dp"
android:layout_height="168dp" />
</LinearLayout>
</ScrollView>
package com.example.reglayout;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
20
import android.widget.TextView;
import android.widget.Toast;
import android.os.Bundle;
import java.util.Calendar;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bindViews();
setViewActions();
prepareDatePickerDialog();
21
private void bindViews()
firstnameEdittext=(EditText)findViewById(R.id.firstname_edittext);
lastnameEdittext=(EditText)findViewById(R.id.lastname_edittext);
emailEdittext=(EditText)findViewById(R.id.email_edittext);
passEdittext=(EditText)findViewById(R.id.password_edittext);
passAgainEdittext=(EditText)findViewById(R.id.password_again_edittext);
birthdayEdittext=(EditText)findViewById(R.id.birthday_edittext);
genderRadioGroup=(RadioGroup)findViewById(R.id.gender_radiogroup);
registerButton=(Button)findViewById(R.id.register_button);
textView = (TextView)findViewById(R.id.text_display);
birthdayEdittext.setOnClickListener((View.OnClickListener) this);
registerButton.setOnClickListener((View.OnClickListener) this);
Calendar calendar=Calendar.getInstance();
//Create datePickerDialog with initial date which is current and decide what happens when a
date is selected.
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
22
//When a date is selected, it comes here.
birthdayEdittext.setText(dayOfMonth+"/"+monthOfYear+"/"+year);
datePickerDialog.dismiss();
},
calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_M
ONTH));
String firstname=firstnameEdittext.getText().toString();
String lastname=lastnameEdittext.getText().toString();
String email=emailEdittext.getText().toString();
String pass=passEdittext.getText().toString();
String passAgain=passAgainEdittext.getText().toString();
String birthday=birthdayEdittext.getText().toString();
//Get gender
RadioButton selectedRadioButton =
(RadioButton)findViewById(genderRadioGroup.getCheckedRadioButtonId());
23
//Check if pass and passAgain are the same
if(pass.equals(passAgain)){
textView.setText(message);
else
Toast.makeText(this,"passwords_must_be_the_same",Toast.LENGTH_SHORT).show();
else
Toast.makeText(this,"no_field_can_be_empty",Toast.LENGTH_SHORT).show();
@Override
switch (v.getId()){
case R.id.birthday_edittext:
datePickerDialog.show();
break;
case R.id.register_button:
showToastWithFormValues();
break;
24
OUTPUT
25
PROGRAM 6
AIM
Design an android application to create page using Intent and one Button , one edittext and pass the
Values from one Activity to second Activity.
PROGRAM
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/send_text_id"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:hint="Input"
android:textSize="25dp"
android:textStyle="bold" />
<Button
android:id="@+id/send_button_id"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="150dp"
26
android:layout_marginTop="150dp"
android:text="send"
android:textStyle="bold" />
</RelativeLayout>
package com.example.intentsactivity;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.*;
EditText send_text;
Button send_button;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send_button = findViewById(R.id.send_button_id);
send_text = findViewById(R.id.send_text_id);
send_button.setOnClickListener(v ->{
intent.putExtra("message_key", str);
startActivity(intent);
});
27
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.geeksforgeeks.navedmalik.sendthedata.Second_activity">
<TextView
android:id="@+id/received_value_id"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:textSize="40sp"
android:textStyle="bold"
android:layout_marginStart="40dp" />
</RelativeLayout>
package com.example.intentsactivity;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.*;
import android.os.Bundle;
import android.content.Intent;
28
public class second_activity extends AppCompatActivity {
TextView receiver_msg;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
receiver_msg = findViewById(R.id.received_value_id);
String str=intent.getStringExtra("message_key");
receiver_msg.setText(str);
OUTPUT
29
PROGRAM 7
AIM
PROGRAM
<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">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Music Player"
android:textSize="35dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
30
android:id="@+id/imageView"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/forward"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pause"
android:id="@+id/button2"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/imageView"
android:layout_alignStart="@+id/imageView" />
<Button
android:layout_width="wrap_content"
31
android:layout_height="wrap_content"
android:text="@string/back"
android:id="@+id/button3"
android:layout_alignTop="@+id/button2"
android:layout_toRightOf="@+id/button2"
android:layout_toEndOf="@+id/button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rewind"
android:id="@+id/button4"
android:layout_alignTop="@+id/button3"
android:layout_toRightOf="@+id/button3"
android:layout_toEndOf="@+id/button3" />
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:layout_alignLeft="@+id/textview"
android:layout_alignStart="@+id/textview"
android:layout_alignRight="@+id/textview"
android:layout_alignEnd="@+id/textview"
android:layout_above="@+id/button" />
32
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView2"
android:layout_above="@+id/seekBar"
android:layout_toLeftOf="@+id/textView"
android:layout_toStartOf="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView3"
android:layout_above="@+id/seekBar"
android:layout_alignRight="@+id/button4"
android:layout_alignEnd="@+id/button4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
33
android:text="Medium Text"
android:id="@+id/textView4"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_centerHorizontal="true" />
</RelativeLayout>
package com.example.multimedia;
import androidx.appcompat.app.AppCompatActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import java.util.concurrent.TimeUnit;
34
private double startTime = 0;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button);
b2 = (Button) findViewById(R.id.button2);
b3 = (Button)findViewById(R.id.button3);
b4 = (Button)findViewById(R.id.button4);
iv = (ImageView)findViewById(R.id.imageView);
tx1 = (TextView)findViewById(R.id.textView2);
tx2 = (TextView)findViewById(R.id.textView3);
tx3 = (TextView)findViewById(R.id.textView4);
tx3.setText("song.mp3");
seekbar = (SeekBar)findViewById(R.id.seekBar);
seekbar.setClickable(false);
b2.setEnabled(false);
35
b3.setOnClickListener(new View.OnClickListener() {
@Override
Toast.makeText(getApplicationContext(), "Playing
sound",Toast.LENGTH_SHORT).show();
mediaPlayer.start();
finalTime = mediaPlayer.getDuration();
startTime = mediaPlayer.getCurrentPosition();
if (oneTimeOnly == 0) {
seekbar.setMax((int) finalTime);
oneTimeOnly = 1;
TimeUnit.MILLISECONDS.toMinutes((long) finalTime),
TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long)
finalTime)))
);
TimeUnit.MILLISECONDS.toMinutes((long) startTime),
TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long)
startTime)))
);
seekbar.setProgress((int)startTime);
myHandler.postDelayed(UpdateSongTime,100);
36
b2.setEnabled(true);
b3.setEnabled(false);
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
Toast.makeText(getApplicationContext(), "Pausing
sound",Toast.LENGTH_SHORT).show();
mediaPlayer.pause();
b2.setEnabled(false);
b3.setEnabled(true);
});
b1.setOnClickListener(new View.OnClickListener() {
@Override
if((temp+forwardTime)<=finalTime){
mediaPlayer.seekTo((int) startTime);
}else{
37
}
});
b4.setOnClickListener(new View.OnClickListener() {
@Override
if((temp-backwardTime)>0){
mediaPlayer.seekTo((int) startTime);
}else{
});
startTime = mediaPlayer.getCurrentPosition();
TimeUnit.MILLISECONDS.toMinutes((long) startTime),
TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
38
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) startTime)))
);
seekbar.setProgress((int)startTime);
myHandler.postDelayed(this, 100);
};
OUTPUT
39
PROGRAM 8
AIM
PROGRAM
<LinearLayout 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="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
tools:context=".Program8">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:layout_marginBottom="30dp"
android:inputType="textPersonName"
android:text="Name" />
40
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
</LinearLayout>
package com.example.androidlabrecord;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;
TextToSpeech tts;
@Override
super.onCreate(savedInstanceState);
41
setContentView(R.layout.activity_program8);
button.setOnClickListener(new View.OnClickListener() {
@Override
@Override
if(i!=TextToSpeech.ERROR){
tts.setLanguage(Locale.US);
tts.speak(text,TextToSpeech.QUEUE_FLUSH,null);
});
});
42
OUTPUT
43
PROGRAM 9
AIM
Create a user registration application that stores the user details in a database table.
PROGRAM
<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"
android:padding="10dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/txttitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24dp"
android:layout_marginTop="20dp" />
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:textSize="24dp"
44
android:layout_below="@+id/txttitle"
android:inputType="textPersonName"/>
<EditText
android:id="@+id/contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="contact"
android:textSize="24dp"
android:layout_below="@+id/name"
android:inputType="number"/>
<EditText
android:id="@+id/dobs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Date of birth"
android:textSize="24dp"
android:layout_below="@+id/contact"
android:inputType="date"/>
<Button
android:id="@+id/inserts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="INSERT"
android:textSize="24dp"
android:layout_marginTop="30dp"
45
android:layout_below="@+id/dobs"/>
<Button
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="VIEW"
android:textSize="24dp"
android:layout_marginTop="30dp"
android:layout_below="@+id/inserts"/>
</RelativeLayout>
package com.example.sqlliteapplication;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import java.lang.*;
import java.util.Date;
EditText name,contact,dobs;
Button insert,view;
@Override
46
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.name);
contact = findViewById(R.id.contact);
dobs = findViewById(R.id.dobs);
insert = findViewById(R.id.inserts);
view = findViewById(R.id.view);
insert.setOnClickListener(new View.OnClickListener() {
@Override
Boolean checkinsertdata;
if (checkinsertdata){
else{
});
view.setOnClickListener(new View.OnClickListener() {
47
@Override
Cursor res;
res = DB.getData();
if(res.getCount()==0){
return;
else{
while(res.moveToNext()){
StringBuffer append;
buffer.append("Name: ".concat(res.getString(0))+"\n");
buffer.append("Contact: ".concat(res.getString(1)+"\n"));
buffer.append("DOB :".concat(res.getString(2)+"\n\n"));
builder.setCancelable(true);
builder.setTitle("User Entries");
builder.setMessage(buffer.toString());
builder.show();
});
48
}
package com.example.sqlliteapplication;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.Date;
@Override
@Override
SQLiteDatabase DB = this.getWritableDatabase();
contentValues.put("name", name);
contentValues.put("contact", contact);
49
contentValues.put("dob", String.valueOf(dob));
if(results == -1)
return false;
else
return true;
SQLiteDatabase DB = this.getWritableDatabase();
return cursor;
OUTPUT
50
PROGRAM 10
AIM
Create sample application with login module (check username and password). On successful login,
change TextView “Login successful”, on login fail, alert user using Toast “Login failed”..
PROGRAM
<LinearLayout 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="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
tools:context=".Program9">
<EditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="60dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="Username" />
<EditText
android:id="@+id/passwordEditText"
51
android:layout_width="match_parent"
android:layout_height="60dp"
android:ems="10"
android:inputType="textPassword"
android:hint="Password" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />
<TextView
android:id="@+id/statusTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="Status" />
</LinearLayout>
package com.example.androidlabrecord;
import androidx.appcompat.app.AppCompatActivity;
52
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
String myUsername="labrecord";
String myPass="labrecord";
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_program9);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
53
if (username.equals(myUsername) && password.equals(myPass)) {
statusTextView.setText("Login successful");
} else {
});
OUTPUT
54
PROGRAM 11
AIM
PROGRAM
<LinearLayout 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"
android:orientation="vertical"
android:layout_gravity="center"
tools:context=".program11">
<EditText
android:id="@+id/ph"
android:layout_width="match_parent"
android:layout_height="60dp"
android:ems="10"
android:inputType="textPersonName"
<EditText
android:id="@+id/msg"
android:layout_width="match_parent"
55
android:layout_height="60dp"
android:ems="10"
android:inputType="textPersonName"
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
</LinearLayout>
package com.example.androidlabrecord;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.widget.EditText;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_program11);
56
EditText ph=findViewById(R.id.ph);
EditText msg=findViewById(R.id.msg);
OUTPUT
57
PROGRAM 12
AIM
<androidx.constraintlayout.widget.ConstraintLayout
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=".Program12">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.androidlabrecord;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
58
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_program12);
.findFragmentById(R.id.map);
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
mMap = googleMap;
});
59
OUTPUT
60