Professional Documents
Culture Documents
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="STUDENTS INFORMATION"
android:textStyle="bold"
android:background="@color/purple_500"/>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/design_default_color_on_primary">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/teal_200"
android:text="Students number"
android:textStyle="bold" />
<TextView
android:layout_width="134dp"
android:layout_height="match_parent"
android:text="Name"
android:textStyle="bold"
android:background="@color/teal_200"/>
<TextView
android:layout_width="137dp"
android:layout_height="29dp"
android:background="@color/teal_200"
android:text=" Marks"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Student 1:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Student 2:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content”/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Student 3:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Student 4:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Student 5:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Student 6:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content”/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Student 7:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Student 8:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Student 9:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Student 10:"
android:textColor="#86AD33"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
Mainactivity.java
package com.example.exp5_1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Output:
Q2.Write a program to display all the data types in object-oriented programming using Frame
layout.
Manifest code:-
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:layout_width="match_parent"
android:layout_height="66dp"
android:text="DATA TYPES"
android:textSize="25dp"
android:textStyle="bold"
android:textAlignment="center"
android:textColor="@color/teal_700"/>
<TextView
android:id="@+id/pd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:text="Primitive"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@color/purple_200"/>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="105dp"
android:layout_marginLeft="70dp"
android:layout_marginTop="110dp"
android:foregroundGravity="fill_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1) Integer" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2) Float" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3) Boolean" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4) Character" />
</androidx.appcompat.widget.LinearLayoutCompat>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|fill_vertical"
android:layout_marginLeft="200dp"
android:layout_marginTop="80dp"
android:layout_toRightOf="@+id/pd"
android:text="Non-Primitive"
android:textColor="@color/purple_200"
android:textSize="20dp"
android:textStyle="bold" />
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="105dp"
android:layout_marginLeft="280dp"
android:layout_marginTop="110dp"
android:foregroundGravity="fill_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1) Class" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2) Object" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3) Array" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4) Interface" />
</androidx.appcompat.widget.LinearLayoutCompat>
</FrameLayout>
Mainactivity.java
package com.example.datatypes;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Output:
Practical No. 7:Develop a program to implement TextView & Edit Text.
Q1. Write a program to accept username and password from the end user using Text View and
Edit Text.
Manifest code:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndriodDevelopment"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
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"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Username"
android:layout_marginTop="120dp"
android:layout_marginLeft="70dp"
android:textStyle="bold"
android:textSize="25dp"/>
<EditText
android:id="@+id/uname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="7dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter password"
android:layout_marginTop="0dp"
android:layout_marginLeft="70dp"
android:textStyle="bold"
android:textSize="25dp"/>
<EditText
android:id="@+id/pass1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="7dp"/>
<Button
android:id="@+id/submit1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit"
android:textAlignment="center"
android:layout_marginTop="7dp"
android:layout_marginLeft="105dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultView"
android:layout_marginTop="10dp"
android:layout_marginLeft="70dp"
android:textStyle="bold"
android:textSize="25dp"/>
</androidx.appcompat.widget.LinearLayoutCompat>
Activitymain.java
package com.example.user_pass;
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;
}
}
Output:
Q2. Write a program to accept and display personal information of the student.
Manifest code:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndriodDevelopment"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="40dp"
android:orientation="vertical" android:id="@+id/linearlayout" >
<EditText
android:id="@+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:ems="10"
android:hint="Name"
android:inputType="text"
android:selectAllOnFocus="true" />
<EditText
android:id="@+id/txtPwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password 0 to 9"
android:inputType="numberPassword" />
<EditText
android:id="@+id/txtEmai"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/txtDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:ems="10"
android:hint="Birth Date"
android:inputType="date" />
<EditText
android:id="@+id/txtPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Phone Number"
android:inputType="phone"/>
<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit"
android:textSize="16sp"
android:textStyle="normal|bold"
android:layout_marginLeft="60dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultView"
android:layout_marginTop="25dp"
android:textSize="15dp"/>
</LinearLayout>
Activitymain.java
package com.example.student_info;
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;
public class MainActivity extends AppCompatActivity {
Button btnSubmit;
EditText name,password,email,dob,phoneno;
TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name=(EditText)findViewById(R.id.txtName);
password = (EditText)findViewById(R.id.txtPwd);
email = (EditText)findViewById(R.id.txtEmai);
dob = (EditText)findViewById(R.id.txtDate);
phoneno= (EditText)findViewById(R.id.txtPhone);
btnSubmit = (Button)findViewById(R.id.btnSend);
result = (TextView)findViewById(R.id.resultView);
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (name.getText().toString().isEmpty() || password.getText().toString().isEmpty() ||
email.getText().toString().isEmpty() || phoneno.getText().toString().isEmpty() ||
dob.getText().toString().isEmpty()) {
result.setText("Please Fill All the Details");
}
else {
result.setText("Name - " + name.getText().toString() + " \n" + "Password - " +
password.getText().toString()+ " \n" + "E-Mail - " + email.getText().toString() + " \n" + "DOB - " +
dob.getText().toString()+ " \n" + "Contact - " + phoneno.getText().toString());
}
}
});
}
}
Output:
Practical No. 8: Develop a program to implement Auto Complete Text View.
Exercise:
Q1. Write a program to create a first display screen of any search engine using AutoComplete
Text View.
Manifest code:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndriodDevelopment"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
Activity_main.xml
<AutoCompleteTextView
android:id="@+id/actv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter a fruits name:"
android:layout_marginLeft="20dp"
android:layout_marginTop="40dp"/>
</LinearLayout>
MainActivity.java
package com.example.student_info;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,fruits);
AutoCompleteTextView actv=(AutoCompleteTextView)findViewById(R.id.actv1);
actv.setThreshold(1);
actv.setAdapter(adapter);
actv.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int i, long l) {
Toast.makeText(getApplicationContext(), "Selected Item" + parent.getSelectedItem(),
Toast.LENGTH_SHORT).show();
}
});
}
}
Output:
Q2. Write a program to display all the subjects of sixth semester using Auto Complete Text View.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="40dp"
android:orientation="vertical"
android:id="@+id/linearlayout" >
<AutoCompleteTextView
android:id="@+id/actv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter a subjects name:"
android:layout_marginLeft="20dp"
android:layout_marginTop="40dp"/>
</LinearLayout>
MainActivity.java
package com.example.student_info;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Toast;
<ToggleButton
android:id="@+id/toggle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="146dp"
android:layout_marginTop="263dp"
android:drawableRight="@mipmap/ic_launcher_round"
android:padding="7dp"
android:textColor="@color/teal_700" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="100dp"
android:layout_marginTop="220dp"
android:text="Bluetooth Status: "
android:textColor="@color/purple_500"
android:textSize="20dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bluetooth Status: "
android:layout_marginTop="200dp"
android:textColor="@color/design_default_color_error"
android:textSize="20dp" />
</RelativeLayout>
MainActivity.java
package com.example.datatypes;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.ToggleButton;
Output:
Practical No. 10: Develop a program to implement login window using above UI
controls.
Exercise:
Q1.Write a program to create a login form for a social networking site.
Manifest code:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndriodDevelopment"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/white">
<ImageView
android:layout_width="290dp"
android:layout_height="290dp"
android:layout_marginTop="25dp"
android:layout_marginLeft="50dp"
android:src="@drawable/fblogo"/>
<EditText
android:id="@+id/et1"
android:layout_width="389dp"
android:layout_height="wrap_content"
android:hint="Username or email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/et2"
android:layout_width="397dp"
android:layout_height="wrap_content"
android:hint="password"
android:inputType="numberPassword"/>
<Button
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="35dp"
android:layout_marginRight="20dp"
android:backgroundTint="#5c6bc0"
android:padding="10dp"
android:text="Log In"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<TextView
android:id="@+id/txtSignUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Sign Up for Facebook"
android:textColor="@color/teal_200" />
<TextView
android:id="@+id/txtForgotPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:text="Forgot Password?"
android:textColor="@color/teal_200"
android:textStyle="normal"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
MainActivity.java
package com.example.loginform;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
Output:
Q2. Write a program to create a login form for student registration system.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">
<TextView
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Regestration"
android:layout_gravity="center"
android:textSize="50dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/name"
android:layout_marginTop="40dp"
android:hint="Name"
android:inputType="textPersonName"
android:minHeight="48dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Surname"
android:inputType="textPersonName"
android:minHeight="48dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress"
android:minHeight="48dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Password"
android:inputType="textPassword"
android:minHeight="48dp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Regester now"
android:id="@+id/btn" />
</LinearLayout>
MainActivity.java
package com.example.gridview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText name1;
Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button) findViewById(R.id.btn);
name1 = (EditText) findViewById(R.id.name);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = name1.getText().toString();
Toast.makeText(getApplicationContext(), "Thanks,"+name+" for Regestration",
Toast.LENGTH_SHORT).show();
}
});
}
}
Output:
Practical No: 11:Develop a program to implement CheckBox.
Exercise;
Q1.Write a program to show five checkboxes and toast selected checkboxes.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity"
android:orientation="vertical">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chk1"
android:onClick="onCheckboxClicked"
android:layout_marginLeft="40dp"
android:layout_marginTop="60dp"
android:text="MAD"
android:textSize="20dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chk2"
android:onClick="onCheckboxClicked"
android:layout_marginLeft="40dp"
android:text="PWP"
android:textSize="20dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chk3"
android:onClick="onCheckboxClicked"
android:layout_marginLeft="40dp"
android:text="MAN"
android:textSize="20dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chk4"
android:onClick="onCheckboxClicked"
android:layout_marginLeft="40dp"
android:text="PHP"
android:textSize="20dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chk5"
android:onClick="onCheckboxClicked"
android:layout_marginLeft="40dp"
android:text="ETI"
android:textSize="20dp"/>
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Details"
android:textAlignment="center"
android:layout_marginLeft="60dp"/>
</LinearLayout>
Mainactivity.java
package com.example.checkbox5;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button b1;
CheckBox ch1,ch2,ch3,ch4,ch5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ch1 = (CheckBox) findViewById(R.id.chk1);
ch2 = (CheckBox) findViewById(R.id.chk2);
ch3 = (CheckBox) findViewById(R.id.chk3);
ch4 = (CheckBox) findViewById(R.id.chk4);
ch5 = (CheckBox) findViewById(R.id.chk5);
b1 = (Button) findViewById(R.id.btn1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String result = "Selected subjects:";
if (ch1.isChecked()) {
result += "/nMAD";
} if (ch2.isChecked()) {
result += "/nPWP";
} if (ch3.isChecked()) {
result += "/nMAN";
} if (ch4.isChecked()) {
result += "/nPHP";
}
if (ch5.isChecked()) {
result += "ETI";
}Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();}
});}
public void onCheckboxClicked(View view){
boolean checked = ((CheckBox) view).isChecked();
String str="";
switch (view.getId()){
case R.id.chk1:
str=checked?"MAD Selected":"MAD Deselected";
break;
case R.id.chk2:
str=checked?"PWP Selected":"PWP deselected";
break;
case R.id.chk3:
str=checked?"MAN selected":"MAN deselected";
break;
case R.id.chk4:
str=checked?"PHP selected":"PHP deselected";
break;
case R.id.chk5:
str=checked?"ETI selected":"ETI deselected";
break;
}
Toast.makeText(getApplicationContext(),str, Toast.LENGTH_SHORT).show();
}
}
Output:
Practical No. 12: Develop a program to implement Radio Button and Radio
Group.
Exercise:
Q1. Write the program to show the following output. First two radio buttons are without taking
radio group and next two are with using radio group. Note the changes between this two. Also
toast which radio button has been selected.
Manifest code:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndriodDevelopment"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
Activity_main.xml:-
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">
<TextView
android:layout_marginTop="80dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="single radio button"
android:gravity="center"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio button1"
android:layout_marginLeft="80dp"
android:onClick="onButtonClick"
android:id="@+id/srb1"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio button2"
android:layout_marginLeft="80dp"
android:onClick="onButtonClick"
android:id="@+id/srb2"/>
<TextView
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="grouped radiio button"
android:gravity="center"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:onClick="onButtonClick"
android:id="@+id/male"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onButtonClick"
android:text="female"
android:id="@+id/female"/>
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:text="Selected"
android:id="@+id/btn"/>
</LinearLayout>
Mainactivity.java
package com.example.andrioddevelopment;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
RadioButton rb1,rb2,male,female;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rb1 = (RadioButton) findViewById(R.id.srb1);
rb2 = (RadioButton) findViewById(R.id.srb2);
male = (RadioButton) findViewById(R.id.male);
female = (RadioButton) findViewById(R.id.female);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String result = "Selected options: ";
if(rb1.isChecked()){
result += "Radio button1\n";
}if(rb2.isChecked()){
result += "Radio button2\n";
}if(male.isChecked()){
result += "Male\n";
}if(female.isChecked()){
result += "Female\n";
}
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
}
});
}
public void onButtonClick(View view){
String res = "";
Boolean check = ((RadioButton) view).isChecked();
switch (view.getId()){
case R.id.srb1:
if(check)
res = "Radio Button1";
break;
case R.id.srb2:
if(check)
res = "Radio Button2";
break;
case R.id.male:
if(check)
res = "Male";
break;
case R.id.female:
if(check)
res = "Female";
break;
}
Toast.makeText(getApplicationContext(), res, Toast.LENGTH_SHORT).show();
}
}
Output:
Practical No. 13: Develop a program to implement Progress Bar
Exercise:
Q1. Write a program to display circular progress bar.
Manifest Code:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndriodDevelopment"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
Activity_main.xml:-
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="200dp" />
</LinearLayout>
Mainactivity.java
package com.example.gridview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
Output:
Q2,Write the program to show the following out
Manifest code:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndriodDevelopment"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
Activity_main.xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btn"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Start downloading file"
android:layout_gravity="center"
android:layout_marginTop="30dp"/>
</LinearLayout>
Layoutforprogress.xml
Mainactivity.java
package com.example.gridview;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.os.*;
import android.view.*;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
Button btn;
ProgressBar prgs;
TextView txt1, txt2;
private Handler hdlr = new Handler();
int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LayoutInflater inflat = getLayoutInflater();
View
layout = inflat.inflate(R.layout.layoutforprogress, (ViewGroup)
findViewById(R.id.custom_progress));
prgs = (ProgressBar) layout.findViewById(R.id.prog);
txt1 = (TextView) layout.findViewById(R.id.percent);
txt2 = (TextView) layout.findViewById(R.id.percent2);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Downloading...").setView(layout);
AlertDialog dialog = builder.create();
dialog.show();
i = prgs.getProgress();
new Thread(new Runnable() {
@Override
public void run() {
while (i < 100) {
i += 2;
hdlr.post(new Runnable() {
@Override
public void run() {
prgs.setProgress(i);
txt1.setText(i + "%");
txt2.setText(i + "/100");
}
});
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
}
dialog.dismiss();
}
}).start();
}
});
}
}
Output:-
Practical No. 14: Develop a program to implement List View, Grid View, Image
View and Scroll View.
Exercise:
Q1. Write a program to show the following output. Use appropriate view for the same.
Manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.unitconverterapp">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.UnitConverterApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity_main.xml:-
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="400dp" />
</LinearLayout>
Mainactivity.java
package com.example.gridview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
private ListView listview;
private ArrayAdapter array1;
private String[]
data={"android","java","php","hadoop","sap","python","ajax","C++","ruby","rails","nodejs"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview= (ListView) findViewById(R.id.listview);
array1=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,data);
listview.setAdapter(array1);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
String selected1=(String) adapterView.getItemAtPosition(i);
Toast.makeText(getApplicationContext(),selected1,
Toast.LENGTH_SHORT).show();
}
});
}
}
Output:
Q2. write a program display an image using image view and button as named chaneg image. once
you click on button another image should get diaplayed.
Manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.unitconverterapp">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.UnitConverterApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity_main.xml:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/img1" />
<Button
android:id="@+id/change_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Image"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp" />
</RelativeLayout>
Mainactivity.java
package com.example.gridview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
Activity_main.xml:-
<?xml version="1.0" encoding="utf-8"?>
<GridView 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:id="@+id/gvdetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:columnWidth="110dp"
android:numColumns="auto_fit"
android:verticalSpacing="60dp"
android:horizontalSpacing="15dp"
android:stretchMode="columnWidth"
android:gravity="center">
</GridView>
ImageAdapter.java
package com.example.gridview;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
private final Context mcontext;
public ImageAdapter(Context c){
mcontext=c; }
@Override
public int getCount() {
return thumbImages.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
ImageView imageView=new ImageView(mcontext);
imageView.setLayoutParams(new ViewGroup.LayoutParams(200,200));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8,8,8,8);
imageView.setImageResource(thumbImages[position]);
return imageView;
}
public Integer[] thumbImages={
R.drawable.img1,R.drawable.img2,
R.drawable.img3,R.drawable.img4,
R.drawable.img5,R.drawable.img6,
R.drawable.img1,R.drawable.img2,
R.drawable.img3,R.drawable.img4,
R.drawable.img5,R.drawable.img6,
R.drawable.img1,R.drawable.img2,
R.drawable.img3,R.drawable.img4
};
}
Main_activity.java
package com.example.gridview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gv=(GridView) findViewById(R.id.gvdetails);
gv.setAdapter(new ImageAdapter(this));
gv.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Toast.makeText(MainActivity.this, "Image position:"+position, Toast.LENGTH_SHORT).show();
}
});
}
}
Output:
Q4.Write a program to display a text view using scrollview.
Activity_main.xml:-
package com.example.gridview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Output:
Practical No.15:Develop a program to implement Custom Toast Alert.
Exercise:
Manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.unitconverterapp">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.UnitConverterApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity_main.xml:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello world Toast example"
android:textStyle="bold"/>
<Button
android:id="@+id/toast_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast"
android:layout_gravity="center"
android:layout_marginTop="32dp" />
</RelativeLayout>
Main_activity.java
package com.example.gridview;
import static android.widget.Toast.makeText;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private Button toastButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toastButton = findViewById(R.id.toast_button);
toastButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast toast;
toast=makeText(getApplicationContext(), "Message for you: You have got a mail",
Toast.LENGTH_SHORT);
View view = toast.getView();
view.setBackgroundColor(Color.BLACK);
TextView textView = toast.getView().findViewById(android.R.id.message);
textView.setTextColor(Color.WHITE);
toast.show();
} });
}
}
Output:
Q2.Write a program to display three checkboxes and a button named “order” as shown below.Once
you click on a button it should display different selected checkboxes along with items individual and
total price.
Manifest.xml:-
Activity_main.xml:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<CheckBox
android:id="@+id/checkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pizza"
android:padding="16dp" />
<CheckBox
android:id="@+id/checkbox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coffee"
android:padding="16dp" />
<CheckBox
android:id="@+id/checkbox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Burger"
android:padding="16dp" />
<Button
android:id="@+id/order_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order"
android:layout_gravity="center"
android:layout_marginTop="32dp" />
</LinearLayout>
Main_activity.java
package com.example.gridview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private CheckBox checkbox1;
private CheckBox checkbox2;
private CheckBox checkbox3;
private Button orderButton;
private int price1 = 10;
private int price2 = 20;
private int price3 = 30;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkbox1 = findViewById(R.id.checkbox1);
checkbox2 = findViewById(R.id.checkbox2);
checkbox3 = findViewById(R.id.checkbox3);
orderButton = findViewById(R.id.order_button);
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int totalPrice = 0;
String selectedItems = "";
if (checkbox1.isChecked()) {
totalPrice += price1;
selectedItems += "Item 1: $" + price1 + "\n"; }
if (checkbox2.isChecked()) {
totalPrice += price2;
selectedItems += "Item 2: $" + price2 + "\n";
}
if (checkbox3.isChecked()) {
totalPrice += price3;
selectedItems += "Item 3: $" + price3 + "\n";
}
Toast.makeText(getApplicationContext(), "Selected items:\n" + selectedItems + "Total price: $"
+ totalPrice, Toast.LENGTH_LONG).show();
}
});
}
Output:
Practical No. 16: Develop a program to implement Date and Time Picker.
Exercise
1. Write a program to display following output. Use TimePicker with Spinnermode.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.unitconverterapp">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.UnitConverterApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TimePicker
android:id="@+id/tp1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TimePicker
android:id="@+id/tp2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:timePickerMode="spinner"
android:layout_marginLeft="4dp"/>
<TimePicker
android:id="@+id/tp3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:timePickerMode="spinner" />
</LinearLayout>
</ScrollView>
Java File:
package com.example.gridview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
TimePicker tp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tp = (TimePicker) findViewById(R.id.tp3);
tp.setIs24HourView(true);
}
}
Output:-
Practical No. 17: Develop a program to create an activity
Exercise:
Q1.Write a program to create a Hello World Activity using all lifecycles methods to display
messages using Log d.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.unitconverterapp">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.UnitConverterApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Mainactivity.java:
package com.example.imageview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onStart() {
super.onStart();
Log.d("lifecycle","onStart invoked");
}
@Override
protected void onResume() {
super.onResume();
Log.d("lifecycle","onResume invoked");
}
@Override
protected void onPause() {
super.onPause();
Log.d("lifecycle","onPause invoked");
}
@Override
protected void onStop() {
super.onStop();
Log.d("lifecycle","onStop invoked");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("lifecycle","onRestart invoked");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("lifecycle","onDestroy invoked");
}
}
Output: