Mt Slip Solution All
Mt Slip Solution All
Slip1
Xml file:
<?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"
android:background="@color/white"
android:gravity="center">
<ImageView
android:id="@+id/logo"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@mipmap/ic_launcher"
android:layout_centerInParent="true" />
<TextView
android:id="@+id/app_name"
android:layout_below="@id/logo"
android:layout_centerHorizontal="true"
android:text="My Java App"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginTop="20dp"
android:textColor="@android:color/black" />
</RelativeLayout>
package com.example.splashdemo;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
// Delay and move to MainActivity
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish(); // Prevent returning to this screen
}
}, SPLASH_DURATION);
}
}
package com.example.splashdemo;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
<TextView
android:text="Welcome to the Main Screen!"
android:textSize="20sp"
android:textColor="#000"
android:layout_centerInParent="true" />
</RelativeLayout>
Activitymain file:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.SplashDemo">
Q2.
package com.example.studentdb;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteOpenHelper;
import android.content.ContentValues;
import java.util.ArrayList;
Activitymain file:
package com.example.studentdb;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Xml file:
<?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">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.StudentDB">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Slip 2
Q.1) Create an application that allows the user to enter a number in the textbox. Check whether the
number in the textbox is perfect number or not. Print the message using Toast control.
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text=""
android:textSize="18sp" />
<EditText
android:id="@+id/numberInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/resultTextView"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:hint="Enter a number"
android:inputType="number" />
<Button
android:id="@+id/checkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/numberInputEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text="Check" />
</RelativeLayout>
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultTextView = findViewById(R.id.resultTextView);
numberInputEditText = findViewById(R.id.numberInputEditText);
checkButton = findViewById(R.id.checkButton);
checkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String numberString = numberInputEditText.getText().toString();
if (numberString.isEmpty()) {
showToast("Please enter a number.");
return;
}
<TextView
android:id="@+id/display"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="@android:color/white"
android:elevation="4dp"
android:gravity="end"
android:padding="8dp"
android:textColor="@android:color/black"
android:textSize="24sp" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/display"
android:rowCount="5"
android:columnCount="4"
android:padding="8dp"
android:layout_marginTop="8dp">
<Button
android:id="@+id/btn3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_rowWeight="1"
android:layout_column="2"
android:layout_columnWeight="1"
android:text="3" />
<Button
android:id="@+id/btnMultiply"
android:text="*"
android:layout_column="3"
android:layout_row="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_width="0dp"/>
<Button
android:id="@+id/btn0"
android:text="0"
android:layout_column="0"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_width="0dp"/>
<Button
android:id="@+id/btnDecimal"
android:text="."
android:layout_column="1"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_width="0dp"/>
<Button
android:id="@+id/btnEquals"
android:text="="
android:layout_column="2"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_width="0dp"/>
<Button
android:id="@+id/btnDivide"
android:text="÷"
android:layout_column="3"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_width="0dp"/>
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Stack;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display = findViewById(R.id.display);
input = new StringBuilder();
if (ch == '(') {
operators.push(ch);
} else if (Character.isDigit(ch) || ch == '.') {
StringBuilder num = new StringBuilder();
while (i < expression.length() &&
(Character.isDigit(expression.charAt(i)) || expression.charAt(i) == '.')) {
num.append(expression.charAt(i));
i++;
}
i--;
operands.push(Double.parseDouble(num.toString()));
} else if (ch == ')') {
while (operators.peek() != '(') {
double result = applyOperator(operators.pop(), operands.pop(),
operands.pop());
operands.push(result);
}
operators.pop(); // Pop '('
} else {
while (!operators.isEmpty() && precedence(ch) <=
precedence(operators.peek())) {
double result = applyOperator(operators.pop(), operands.pop(),
operands.pop());
operands.push(result);
}
operators.push(ch);
}
}
while (!operators.isEmpty()) {
double result = applyOperator(operators.pop(), operands.pop(),
operands.pop());
operands.push(result);
}
return operands.pop();
}
Slip 3
Q.1) Create an application that allows the user to enter a number in the textbox. Check whether the
number in the textbox is Armstrong or not. Print the message accordingly in the label control.
<EditText
android:id="@+id/numberInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a number"
android:inputType="number" />
<Button
android:id="@+id/checkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/numberInputEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Check"
android:onClick="checkArmstrongNumber" />
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/checkButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text=""
android:textSize="18sp" />
</RelativeLayout>
JAVA MAIN ACTIVITY FILE
package com.example.slip3a;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
if (numberString.isEmpty()) {
displayResult(false); // Empty input is not an Armstrong number
return;
}
Q.2) Create an Android application which examine a phone number entered by a user with the given
format. • Area code should be one of the following: 040, 041, 050, 0400, 044 • There should 6 - 8
numbers in telephone number (+ area code)
XML MAIN ACTIVITY FILE
<?xml version="1.0" encoding="utf-8"?>
<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/phoneNumberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter phone number"
android:inputType="phone" />
<Button
android:id="@+id/checkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/phoneNumberEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Check"
android:onClick="checkPhoneNumber" />
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/checkButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text=""
android:textSize="18sp" />
</RelativeLayout>
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
if (phoneNumber.isEmpty()) {
displayResult(false); // Empty input is not a valid phone number
return;
}
Slip 4 Q1.
Xml file:
<?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"
android:padding="16dp">
</RelativeLayout>
Java file:
package com.example.imageswitcherapp;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageSwitcher = findViewById(R.id.imageSwitcher);
nextImageButton = findViewById(R.id.nextImageButton);
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.ImagesSwitcherApp">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Slip 5
Q.1) Java Android Program to Demonstrate Alert Dialog Box.
</RelativeLayout>
import android.os.Build;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button but = (Button) findViewById(R.id.button);
but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Create an alert dialog box
AlertDialog.Builder builder = new
AlertDialog.Builder(MainActivity.this);
// Set the value for the positive reaction from the user
// You can also set a listener to call when it is pressed
builder.setPositiveButton("ok", null);
// The message
builder.setMessage("welcome");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
Q.2) Create an Android application which will ask the user to input his / her name. A message should
display the two items concatenated in a label. Change the format of the label using radio buttons and
check boxes for selection. The user can make the label text bold, underlined or italic as well as
change its color. Also include buttons to display the message in the label, clear the text boxes as well
as label. Finally exit.
XML FILE
<?xml version="1.0" encoding="utf-8"?>
<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/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name"
android:layout_margin="16dp"
android:inputType="text" />
<Button
android:id="@+id/displayButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display Message"
android:layout_below="@id/nameEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:onClick="displayMessage" />
<CheckBox
android:id="@+id/boldCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bold"
android:layout_below="@id/displayButton"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp" />
<CheckBox
android:id="@+id/italicCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Italic"
android:layout_below="@id/displayButton"
android:layout_toEndOf="@id/boldCheckBox"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp" />
<CheckBox
android:id="@+id/underlineCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Underline"
android:layout_below="@id/displayButton"
android:layout_toEndOf="@id/italicCheckBox"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp" />
<RadioGroup
android:id="@+id/colorRadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/boldCheckBox"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true">
<RadioButton
android:id="@+id/redRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red" />
<RadioButton
android:id="@+id/blueRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue" />
<RadioButton
android:id="@+id/greenRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Green" />
</RadioGroup>
<Button
android:id="@+id/clearButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:layout_below="@id/colorRadioGroup"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:onClick="clearLabel" />
<Button
android:id="@+id/exitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:layout_below="@id/colorRadioGroup"
android:layout_marginTop="16dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="16dp"
android:onClick="exitApp" />
<TextView
android:id="@+id/messageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_below="@id/clearButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:textColor="@android:color/black"
android:textSize="18sp" />
</RelativeLayout>
JAVA FILE
package com.example.slip5b;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nameEditText = findViewById(R.id.nameEditText);
messageTextView = findViewById(R.id.messageTextView);
boldCheckBox = findViewById(R.id.boldCheckBox);
italicCheckBox = findViewById(R.id.italicCheckBox);
underlineCheckBox = findViewById(R.id.underlineCheckBox);
redRadioButton = findViewById(R.id.redRadioButton);
blueRadioButton = findViewById(R.id.blueRadioButton);
greenRadioButton = findViewById(R.id.greenRadioButton);
}
// Function to display the message in the label with the selected format
public void displayMessage(View view) {
String name = nameEditText.getText().toString();
messageTextView.setTextColor(getResources().getColor(android.R.color.black));
messageTextView.setPaintFlags(messageTextView.getPaintFlags() &
(~android.graphics.Paint.UNDERLINE_TEXT_FLAG));
}
Slip 9
Create an application that allows the user to enter a number in the textbox named „getnum‟. Check
whether the number in the textbox „getnum‟ is Palindrome or not. Print the message accordingly in
the label when the user clicks on the button „Check‟.
XML FILE
<?xml version="1.0" encoding="utf-8"?>
<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/getnum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a number"
android:layout_margin="16dp"
android:inputType="number" />
<Button
android:id="@+id/checkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check"
android:layout_below="@id/getnum"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:onClick="checkPalindrome" />
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:textColor="@android:color/black"
android:layout_below="@id/checkButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp" />
</RelativeLayout>
JAVA FILE
package com.example.slip9a;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
while (number != 0) {
int digit = number % 10;
reversedNumber = reversedNumber * 10 + digit;
number /= 10;
}
if (numberString.isEmpty()) {
displayResult(false); // Empty input is not a palindrome
return;
}
ALREADY MENTION
Slip 10
Q.1] Create an application that allows the user to enter a number in the textbox named getnum.
Check whether the number in the textbox getnum is Armstrong or not. Print the message using Toast
control when the user clicks on the button Check.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/ap
k/res/android" xmlns:app="http://schemas.android.com/apk/res-
auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" andr
oid:layout_height="match_parent" android:padding="16dp" tools:context=".MainActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
<EditText android:id="@+id/itemEditText" android:layout_width="ma
tch_parent" android:layout_height="wrap_content" android:hint="A
pple" android:layout_marginBottom="16dp" android:inputType="tex
t"/>
<LinearLayout android:layout_width="match_parent" android:layout
_height="wrap_content" android:orientation="horizontal" android:la
yout_marginBottom="24dp">
<Button android:id="@+id/addButton" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_weight="1" a
ndroid:layout_marginEnd="8dp" android:text="Add to spinner"/>
<Button android:id="@+id/removeButton" android:layout_width="0
dp" android:layout_height="wrap_content" android:layout_weight="
1" android:layout_marginStart="8dp" android:text="Remove from
spinner"/>
</LinearLayout>
<TextView android:layout_width="wrap_content" android:layout_hei
ght="wrap_content" android:text="See Response
Below" android:textSize="16sp" android:layout_marginBottom="8dp
"/>
<Spinner android:id="@+id/itemSpinner" android:layout_width="ma
tch_parent" android:layout_height="wrap_content" android:minHeig
ht="48dp" android:background="@android:drawable/btn_dropdown
"/>
</LinearLayout>
Slip 11
Q.1] Create an Android Application to accept two numbers to calculate its Power and Average. Create
two buttons: Power and Average. Display the appropriate result on the next activity on Button click.
<LinearLayout 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" android:orientation="vertical" android:padding="16dp"
tools:context=".MainActivity">
</LinearLayout>
</LinearLayout>
Q.2] Create an Android Application to perform following string operation according to user selection
of radio button.
</RadioGroup>
</LinearLayout>
Slip 12
Q.1] Construct an Android app that toggles a light bulb ON and OFF when the user clicks on toggle
button.
XML FILE
<?xml version="1.0" encoding="utf-8"?>
<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">
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="OFF"
android:textOn="ON"
android:checked="false"
android:layout_centerInParent="true"
android:onClick="toggleLight" />
</RelativeLayout>
JAVA FILE
package com.example.slip12a;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.widget.ToggleButton;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (isLightOn) {
// Light is turned on
// You can perform actions here to control a real light bulb
Toast.makeText(this, "Light is ON", Toast.LENGTH_SHORT).show();
} else {
// Light is turned off
// You can perform actions here to control a real light bulb
Toast.makeText(this, "Light is OFF", Toast.LENGTH_SHORT).show();
}
}
}
Q.2] Create an Android application which will ask the user to input his / her name. A message should
display the two items concatenated in a label. Change the format of the label using radio buttons and
check boxes for selection. The user can make the label text bold, underlined or italic as well as
change its color. Also include buttons to display the message in the label, clear the text boxes as well
as label. Finally exit.
ALREADY MENTION
Slip 13
Java android program to demonstrate Registration form with validation.
XML FILE
<?xml version="1.0" encoding="utf-8"?>
<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/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:inputType="textPersonName"
android:layout_margin="16dp" />
<EditText
android:id="@+id/mobileEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Mobile Number"
android:inputType="phone"
android:layout_below="@id/nameEditText"
android:layout_margin="16dp" />
<EditText
android:id="@+id/ageEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Age"
android:inputType="number"
android:layout_below="@id/mobileEditText"
android:layout_margin="16dp" />
<EditText
android:id="@+id/addressEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Address"
android:inputType="textPostalAddress"
android:layout_below="@id/ageEditText"
android:layout_margin="16dp" />
<Button
android:id="@+id/registerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:layout_below="@id/addressEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:onClick="registerUser" />
</RelativeLayout>
JAVA FILE
package com.example.slip13a;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nameEditText = findViewById(R.id.nameEditText);
mobileEditText = findViewById(R.id.mobileEditText);
ageEditText = findViewById(R.id.ageEditText);
addressEditText = findViewById(R.id.addressEditText);
}
if (TextUtils.isEmpty(name)) {
nameEditText.setError("Please enter your name");
return;
}
if (TextUtils.isEmpty(mobile)) {
mobileEditText.setError("Please enter your mobile number");
return;
}
if (TextUtils.isEmpty(age)) {
ageEditText.setError("Please enter your age");
return;
}
if (TextUtils.isEmpty(address)) {
addressEditText.setError("Please enter your address");
return;
}
// Perform further actions (e.g., save data to database) if all fields are
valid
// For demonstration, we display a toast message
Toast.makeText(this, "User registered successfully",
Toast.LENGTH_SHORT).show();
}
}
Q.2] Write a Java Android Program to Demonstrate List View Activity with all operations Such as:
Insert, Delete, Search
Slip 14
Q.1] Construct an Android application to accept a number and calculate and display Factorial of a
given number in TextView.
XML FILE
<?xml version="1.0" encoding="utf-8"?>
<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/numberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a number"
android:inputType="number"
android:layout_margin="16dp"/>
<Button
android:id="@+id/calculateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate Factorial"
android:layout_below="@id/numberEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:onClick="calculateFactorial"/>
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:textColor="@android:color/black"
android:layout_below="@id/calculateButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp" />
</RelativeLayout>
JAVA FILE
package com.example.slip14a;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
numberEditText = findViewById(R.id.numberEditText);
resultTextView = findViewById(R.id.resultTextView);
}
if (!inputStr.isEmpty()) {
int number = Integer.parseInt(inputStr);
long factorial = calculateFactorial(number);
resultTextView.setText("Factorial of " + number + " is: " + factorial);
} else {
resultTextView.setText("Please enter a number.");
}
}
Q.2] Create an Android application, which show Login Form. After clicking LOGIN button display the
“Login Successful…” message if username and password is same else display “Invalid Login” message
in Toast Control.
XML FILE
<?xml version="1.0" encoding="utf-8"?>
<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/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:layout_margin="16dp"/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:layout_below="@id/usernameEditText"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"/>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_below="@id/passwordEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:onClick="login"/>
</RelativeLayout>
JAVA FILE
package com.example.slip14b;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usernameEditText = findViewById(R.id.usernameEditText);
passwordEditText = findViewById(R.id.passwordEditText);
}
if (username.equals(password)) {
Toast.makeText(this, "Login Successful", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Invalid Login", Toast.LENGTH_SHORT).show();
}
}
}
slip 19
<RelativeLayout xmlns:android="http://schemas.android.com/apk/re
s/android" xmlns:tools="http://schemas.android.com/tools" android:
layout_width="match_parent" android:layout_height="match_paren
t" android:padding="16dp" tools:context=".MainActivity">
<ImageSwitcher android:id="@+id/imageSwitcher" android:layout_w
idth="385dp" android:layout_height="574dp" android:layout_above=
"@+id/buttonLayout" android:layout_marginBottom="77dp"/>
<LinearLayout android:id="@+id/buttonLayout" android:layout_widt
h="match_parent" android:layout_height="wrap_content" android:la
yout_alignParentBottom="true" android:layout_marginBottom="100
dp" android:gravity="center" android:orientation="horizontal">
<Button android:id="@+id/prevButton" android:layout_width="wrap
_content" android:layout_height="wrap_content" android:layout_ma
rginEnd="16dp" android:text="Previous"/>
<Button android:id="@+id/nextButton" android:layout_width="wrap
_content" android:layout_height="wrap_content" android:layout_ma
rginStart="16dp" android:text="Next"/>
</LinearLayout>
</RelativeLayout>
package slip-4;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageSwitcher = findViewById(R.id.imageSwitcher);
imageSwitcher.setImageResource(images[currentIndex]);
nextButton = findViewById(R.id.nextButton);
prevButton = findViewById(R.id.prevButton);
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentIndex++;
if (currentIndex >= images.length) {
currentIndex = 0;
}
imageSwitcher.setImageResource(images[currentIndex]);
}
});
prevButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentIndex--;
if (currentIndex < 0) {
currentIndex = images.length - 1;
}
imageSwitcher.setImageResource(images[currentIndex]);
}
});
}
}{
}
Slip 25
Q.1] Create an android application for SMS activity.
XML FILE
<?xml version="1.0" encoding="utf-8"?>
<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/phoneNumberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter phone number"
android:inputType="phone"
android:layout_margin="16dp"/>
<EditText
android:id="@+id/messageEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter message"
android:layout_below="@id/phoneNumberEditText"
android:layout_margin="16dp"/>
<Button
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:layout_below="@id/messageEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:onClick="sendSMS"/>
</RelativeLayout>
JAVA FILE
package com.example.slip25a;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phoneNumberEditText = findViewById(R.id.phoneNumberEditText);
messageEditText = findViewById(R.id.messageEditText);
}
Q.2] Create an Android application, which show Login Form in table layout. After clicking LOGIN
button display the “Login Successful…” message if username and password is same else display
“Invalid Login” message in Toast Control.
ALREADY MENTION