You are on page 1of 40

Practical no 4

Que 1.Write a program to display HelloWorld.


activity_main.xml MainActivity.java
<?xml version="1.0" encoding="utf-8"?> package com.firstapp.practicle4;
<androidx.constraintlayout.widget.ConstraintLayout
import androidx.appcompat.app.AppCompatActivity;
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" import android.content.Intent;
xmlns:tools="http://schemas.android.com/tools" import android.os.Bundle;
android:layout_width="match_parent" import android.os.Handler;
android:layout_height="match_parent"
tools:context=".MainActivity" public class MainActivity extends AppCompatActivity {
android:background="@color/teal_200">
<TextView @Override
android:layout_width="wrap_content" protected void onCreate(Bundle savedInstanceState) {
android:layout_height="wrap_content" super.onCreate(savedInstanceState);
android:textSize="23dp" setContentView(R.layout.activity_main);
android:textStyle="bold" getSupportActionBar().hide();
android:fontFamily="@font/amarante" new Handler().postDelayed(new Runnable() {
android:text="Hello World!" @Override
app:layout_constraintBottom_toBottomOf="parent" public void run() {
app:layout_constraintLeft_toLeftOf="parent" Intent i = new Intent(MainActivity.this,
app:layout_constraintRight_toRightOf="parent" Stud_name.class);
app:layout_constraintTop_toTopOf="parent" /> startActivity(i);
</androidx.constraintlayout.widget.ConstraintLayout> finish();
}
}, 3000);
}
}

Manifest.xml Output
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.firstapp.practicle4">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Practicle4">
<activity android:name=".Stud_name"></activity>
<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>

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>

</manifest>
Que 2 Write a program to display student name and marks.
activity_stud.xml Studname.java
<?xml version="1.0" encoding="utf-8"?> package com.firstapp.practicle4;
<LinearLayout import
xmlns:android="http://schemas.android.com/apk androidx.appcompat.app.AppCompatActivity;
/res/android"
import android.os.Bundle;
xmlns:app="http://schemas.android.com/apk/res public class Stud_name extends
-auto" AppCompatActivity {
xmlns:tools="http://schemas.android.com/tools @Override
" protected void onCreate(Bundle
android:layout_width="match_parent" savedInstanceState) {
android:layout_height="match_parent" super.onCreate(savedInstanceState);
tools:context=".Stud_name"
android:orientation="vertical" setContentView(R.layout.activity_stud_name);
android:gravity="center"> getSupportActionBar().hide();
<LinearLayout }
android:layout_width="match_parent" }
android:layout_height="wrap_content"
android:layout_marginLeft="20dp">
<TextView
android:layout_width="150dp" output
android:layout_height="40dp"
android:fontFamily="cursive"
android:gravity="center"
android:text="Student name:-"
android:textSize="20dp"
android:textStyle="bold" />
<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:fontFamily="@font/amarante"
android:text="Hrugved Lakhapati"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp">
<TextView
android:layout_width="150dp"
android:layout_height="40dp"
android:gravity="center"
android:text="Student Marks:-"
android:textSize="20dp"
android:fontFamily="cursive"
android:textStyle="bold" />
<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:fontFamily="@font/amarante"
android:text="92.78"
android:textSize="18dp" />
</LinearLayout>
</LinearLayout>
Practical No 05
Que 1. Write a program to place Name, Age and mobile number linearly (Vertical) on the display screen using
Linear layout.
activity_main.xml MainActivity.java
<?xml version="1.0" encoding="utf-8"?> package com.firstapp.practicle5;
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/ import androidx.appcompat.app.AppCompatActivity;
android"
xmlns:app="http://schemas.android.com/apk/res- import android.os.Bundle;
auto"
xmlns:tools="http://schemas.android.com/tools" public class MainActivity extends
android:layout_width="match_parent" AppCompatActivity {
android:layout_height="match_parent"
tools:context=".MainActivity" @Override
android:orientation="vertical" protected void onCreate(Bundle
android:gravity="center"> savedInstanceState) {
<LinearLayout super.onCreate(savedInstanceState);
android:layout_width="match_parent" setContentView(R.layout.activity_main);
android:layout_height="wrap_content" }
android:layout_marginLeft="20dp"> }
<TextView
android:layout_width="150dp"
android:layout_height="40dp" Manifest.xml
android:fontFamily="cursive"
android:gravity="center" <?xml version="1.0" encoding="utf-8"?>
android:text="Name:-" <manifest
android:textSize="20dp" xmlns:android="http://schemas.android.com/apk/res/
android:textStyle="bold" /> android"
package="com.firstapp.practicle5">
<TextView <application
android:layout_width="match_parent" android:allowBackup="true"
android:layout_height="wrap_content" android:icon="@mipmap/ic_launcher"
android:fontFamily="@font/amarante" android:label="@string/app_name"
android:text="Hrugved Lakhapati"
android:textSize="18dp" /> android:roundIcon="@mipmap/ic_launcher_round"
</LinearLayout> android:supportsRtl="true"
<LinearLayout android:theme="@style/Theme.Practicle5">
android:layout_width="match_parent" <activity android:name=".MainActivity"
android:layout_height="wrap_content" android:exported="true">
android:layout_marginLeft="22dp"> <intent-filter>
<TextView <action
android:layout_width="150dp" android:name="android.intent.action.MAIN" />
android:layout_height="40dp" <category
android:gravity="center" android:name="android.intent.category.LAUNCHER" />
android:text="Age:-" </intent-filter>
android:textSize="20dp" </activity>
android:fontFamily="cursive" <meta-data
android:textStyle="bold" /> android:name="preloaded_fonts"
<TextView
android:layout_width="match_parent" android:resource="@array/preloaded_fonts" />
android:layout_height="wrap_content" </application>
android:fontFamily="@font/amarante" </manifest>
android:text="18"
android:textSize="18dp" />
</LinearLayout>
Output
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp">
<TextView
android:layout_width="150dp"
android:layout_height="40dp"
android:gravity="center"
android:text="Number:-"
android:textSize="20dp"
android:fontFamily="cursive"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/amarante"
android:text="9307816626"
android:textSize="18dp" />
</LinearLayout>
</LinearLayout>
activity_using_absolute.xml using_absolutelayout.java

<?xml version="1.0" encoding="utf-8"?> package com.firstapp.practicle5;


<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk import
/res/android" androidx.appcompat.app.AppCompatActivity;

xmlns:app="http://schemas.android.com/apk/res import android.os.Bundle;


-auto"
public class using_absolutelayput extends
xmlns:tools="http://schemas.android.com/tools AppCompatActivity {
"
android:layout_width="match_parent" @Override
android:layout_height="match_parent" protected void onCreate(Bundle
android:paddingLeft="16dp" savedInstanceState) {
android:paddingTop="16dp" super.onCreate(savedInstanceState);
android:paddingRight="16dp"
tools:context=".using_absolutelayput"> setContentView(R.layout.activity_using_absolu
<TextView telayput);
android:id="@+id/student_name" }
android:layout_width="wrap_content" }
android:layout_height="wrap_content"
android:layout_x="10dp" output
android:layout_y="280dp"

android:fontFamily="@font/big_shoulders_displ
ay_bold"
android:text="Name: Hrugved
Lakhapati"
android:textColor="#000"
android:textSize="25dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="10dp"
android:layout_y="320dp"
android:text="Age:18"

android:fontFamily="@font/big_shoulders_displ
ay_bold"
android:textColor="#000"
android:textSize="25dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="10dp"
android:layout_y="360dp"

android:fontFamily="@font/big_shoulders_displ
ay_bold"
android:text="Mobile
Number:9307816626"
android:textColor="#000"
android:textSize="25dp"/>
</AbsoluteLayout>
Practical No 06
Que 1.Write a program to display 10 students basic information in a table form using Table layout.
/>
activity_main.xml <TextView
android:layout_width="wrap_content"
<?xml version="1.0" encoding="utf-8"?> android:layout_height="wrap_content"
<TableLayout android:layout_weight="1"
xmlns:android="http://schemas.android.com/apk/res/android" android:text=" ME"
xmlns:app="http://schemas.android.com/apk/res-auto" android:textColor="@color/black"
xmlns:tools="http://schemas.android.com/tools" android:textSize="15dp"
android:layout_width="match_parent" />
android:layout_height="match_parent" <TextView
android:layout_marginTop="100dp" android:layout_width="wrap_content"
android:paddingRight="10dp" android:layout_height="wrap_content"
android:paddingLeft="10dp" android:layout_weight="1"
tools:context=".MainActivity"> android:text="1234567890"
<TableRow android:padding="10dp"> android:textColor="@color/black"
<TextView android:textSize="15dp"
android:layout_width="wrap_content" />
android:layout_height="wrap_content" </TableRow>
android:layout_weight="1" <TableRow android:padding="10dp">
android:text="Roll No." <TextView
android:fontFamily="@font/amarante" android:layout_width="wrap_content"
android:textColor="@color/black" android:layout_height="wrap_content"
android:textSize="18dp"/> android:layout_weight="1"
<TextView android:text="03"
android:layout_width="wrap_content" android:textColor="@color/black"
android:layout_height="wrap_content" android:textSize="15dp"
android:layout_weight="1" />
android:text="Student Name" <TextView
android:fontFamily="@font/amarante" android:layout_width="wrap_content"
android:textColor="@color/black" android:layout_height="wrap_content"
android:textSize="18dp"/> android:layout_weight="1"
<TextView android:text="aayush khond"
android:layout_width="wrap_content" android:textColor="@color/black"
android:layout_height="wrap_content" android:textSize="15dp"
android:layout_weight="1" />
android:fontFamily="@font/amarante" <TextView
android:text="Branch" android:layout_width="wrap_content"
android:textColor="@color/black" android:layout_height="wrap_content"
android:textSize="18dp"/> android:layout_weight="1"
<TextView android:text=" EE"
android:layout_width="wrap_content" android:textColor="@color/black"
android:layout_height="wrap_content" android:textSize="15dp"
android:layout_weight="1" />
android:text="Contact No." <TextView
android:fontFamily="@font/amarante" android:layout_width="wrap_content"
android:textColor="@color/black" android:layout_height="wrap_content"
android:textSize="18dp"/> android:layout_weight="1"
</TableRow> android:text="1234567890"
<TableRow android:padding="10dp"> android:textColor="@color/black"
<TextView android:textSize="15dp"
android:layout_width="wrap_content" />
android:layout_height="wrap_content" </TableRow>
android:layout_weight="1" <TableRow android:padding="10dp">
android:text="01" <TextView
android:textColor="@color/black" android:layout_width="wrap_content"
android:textSize="15dp"/> android:layout_height="wrap_content"
<TextView android:layout_weight="1"
android:layout_width="wrap_content" android:text="04"
android:layout_height="wrap_content" android:textColor="@color/black"
android:layout_weight="1" android:textSize="15dp"
android:text="Hrugved Lakhapati" />
android:textColor="@color/black" <TextView
android:textSize="15dp"/> android:layout_width="wrap_content"
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_weight="1"
android:layout_height="wrap_content" android:text="pawan katkhede"
android:layout_weight="1" android:textColor="@color/black"
android:text=" CO" android:textSize="15dp"
android:textColor="@color/black" />
android:textSize="15dp"/> <TextView
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_weight="1" android:text=" ME"
android:text="1234567890" android:textColor="@color/black"
android:textColor="@color/black" android:textSize="15dp"
android:textSize="15dp" />
/> <TextView
</TableRow> android:layout_width="wrap_content"
<TableRow android:padding="10dp"> android:layout_height="wrap_content"
<TextView android:layout_weight="1"
android:layout_width="wrap_content" android:text="1234567890"
android:layout_height="wrap_content" android:textColor="@color/black"
android:layout_weight="1" android:textSize="15dp"
android:text="02" />
android:textColor="@color/black" </TableRow>
android:textSize="15dp" <TableRow android:padding="10dp">
/> <TextView
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_weight="1" android:text="05"
android:text="vishva wagh" android:textColor="@color/black"
android:textColor="@color/black" android:textSize="15dp"
android:textSize="15dp" />
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_weight="1" android:text="08"
android:text="Pranil lonagre" android:textColor="@color/black"
android:textColor="@color/black" android:textSize="15dp"
android:textSize="15dp" />
/> <TextView
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_weight="1" android:text="nitin thakre"
android:text=" CO" android:textColor="@color/black"
android:textColor="@color/black" android:textSize="15dp"
android:textSize="15dp" />
/> <TextView
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_weight="1" android:text=" ME"
android:text="1234567890" android:textColor="@color/black"
android:textColor="@color/black" android:textSize="15dp"
android:textSize="15dp" />
/> <TextView
</TableRow> android:layout_width="wrap_content"
<TableRow android:padding="10dp"> android:layout_height="wrap_content"
<TextView android:layout_weight="1"
android:layout_width="wrap_content" android:text="1234567890"
android:layout_height="wrap_content" android:textColor="@color/black"
android:layout_weight="1" android:textSize="15dp"
android:text="06" />
android:textColor="@color/black" </TableRow>
android:textSize="15dp" <TableRow android:padding="10dp">
/> <TextView
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_weight="1" android:text="09"
android:text="samyak bhojane" android:textColor="@color/black"
android:textColor="@color/black" android:textSize="15dp"
android:textSize="15dp" />
/> <TextView
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_weight="1" android:text="ram patil"
android:text=" ME" android:textColor="@color/black"
android:textColor="@color/black" android:textSize="15dp"
android:textSize="15dp" />
/> <TextView
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_weight="1" android:text=" EE"
android:text="1234567890" android:textColor="@color/black"
android:textColor="@color/black" android:textSize="15dp"
android:textSize="15dp" />
/> <TextView
</TableRow> android:layout_width="wrap_content"
<TableRow android:padding="10dp"> android:layout_height="wrap_content"
<TextView android:layout_weight="1"
android:layout_width="wrap_content" android:text="1234567890"
android:layout_height="wrap_content" android:textColor="@color/black"
android:layout_weight="1" android:textSize="15dp"
android:text="07" />
android:textColor="@color/black" </TableRow>
android:textSize="15dp" <TableRow android:padding="10dp">
/> <TextView
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_weight="1" android:text="10"
android:text="vivek raut" android:textColor="@color/black"
android:textColor="@color/black" android:textSize="15dp"
android:textSize="15dp" />
/> <TextView
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_weight="1" android:text="sham patil"
android:text=" CO" android:textColor="@color/black"
android:textColor="@color/black" android:textSize="15dp"
android:textSize="15dp" />
/> <TextView
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_weight="1" android:text=" IT"
android:text="1234567890" android:textColor="@color/black"
android:textColor="@color/black" android:textSize="15dp"
android:textSize="15dp" />
/> <TextView
</TableRow> android:layout_width="wrap_content"
<TableRow android:padding="10dp"> android:layout_height="wrap_content"
<TextView android:layout_weight="1"
android:text="1234567890"
android:textColor="@color/black"
Output

android:textSize="15dp"
/>
</TableRow>
</TableLayout>

MainActivity.java
package com.firstapp.practicle6;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent mInHome = new Intent(MainActivity.this,frame_layout.class);
MainActivity.this.startActivity(mInHome);
MainActivity.this.finish();
}
},3000);
}
}

Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.firstapp.practicle6">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Practicle6">
<activity android:name=".frame_layout"></activity>
<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>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts"/>
</application>
</manifest>
Que 2. Write a program to display all the data types in object-oriented programming using Frame layout.

activity_frame_layout.xml Frame_layout.java
package com.firstapp.practicle6;
<FrameLayout
import androidx.appcompat.app.AppCompatActivity;
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
import android.os.Bundle;
xmlns:tools="http://schemas.android.com/tools"
public class frame_layout extends AppCompatActivity {
android:layout_width="match_parent"
android:layout_height="match_parent" @Override
protected void onCreate(Bundle savedInstanceState) {
tools:context=".frame_layout"
super.onCreate(savedInstanceState);
android:padding="10dp">
<TextView setContentView(R.layout.activity_frame_layout);
android:layout_width="wrap_content" }
android:layout_height="wrap_content" }
android:text="float"
android:textSize="30dp"
android:fontFamily="@font/bubblegum_sans" output
android:textColor="@color/black"
android:textStyle="bold"
android:layout_gravity="right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="boolean"
android:textSize="30dp"
android:fontFamily="@font/bubblegum_sans"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_gravity="right|center_vertical"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="void"
android:textSize="30dp"
android:fontFamily="@font/bubblegum_sans"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_gravity="bottom"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/bubblegum_sans"
android:text="int"

android:textColor="@color/black"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="char"
android:textSize="30dp"
android:fontFamily="@font/bubblegum_sans"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_gravity="top|center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pointer"
android:textSize="30dp"
android:fontFamily="@font/bubblegum_sans"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_gravity="bottom|center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="array"
android:textSize="30dp"
android:fontFamily="@font/bubblegum_sans"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_gravity="bottom|right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="string"
android:textSize="30dp"
android:fontFamily="@font/bubblegum_sans"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_gravity="left|center_vertical"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="double"
android:textSize="30dp"
android:fontFamily="@font/bubblegum_sans"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_gravity="center_vertical|center_horizontal"/>
</FrameLayout>
Practicle No 07
Que 1.Write a program to accept username and password from the end user using TextView and Edit Text.
activity_main.xml
setContentView(R.layout.activity_main);
<?xml version="1.0" encoding="utf-8"?>
b = findViewById(R.id.btn1);user = findViewById(R.id.user);
<TableLayout
pass = findViewById(R.id.pass);
xmlns:android="http://schemas.android.com/apk/res/
Handler handler=new Handler();
android"
handler.postDelayed(new Runnable() {
xmlns:app="http://schemas.android.com/apk/res-
@Override
auto"
public void run() {
xmlns:tools="http://schemas.android.com/tools"
Intent mInHome = new
android:layout_width="match_parent"
android:layout_height="match_parent" Intent(MainActivity.this,accept_display.class);
android:padding="50dp" MainActivity.this.startActivity(mInHome);
android:gravity="center" MainActivity.this.finish();
tools:context=".MainActivity"> }
<TextView },3000);
android:layout_width="wrap_content" b.setOnClickListener(new View.OnClickListener() {
android:layout_height="wrap_content" @Override
android:fontFamily="@font/delius" public void onClick(View v) {
android:gravity="center" if
android:text="Login Page" (!user.getText().toString().isEmpty()&&!pass.getText().toString().isEmpty
android:textSize="25dp" /> ()) {
<TableRow Toast.makeText(getApplicationContext(), "Login
android:layout_width="match_parent" Successfull!!", Toast.LENGTH_SHORT).show();
android:layout_height="wrap_content" } else {
android:gravity="center_horizontal"> Toast.makeText(getApplicationContext(), "Please enter all
<TextView information", Toast.LENGTH_SHORT).show();
android:layout_height="wrap_content" }
android:layout_weight="1"
android:gravity="center" }
android:textStyle="bold" });
android:fontFamily="@font/delius" }
android:text="Enter UserName:" /> }
<EditText
android:id="@+id/user"
android:layout_height="wrap_content" Output
android:layout_weight="1"
android:fontFamily="@font/amarante"
android:hint="abc@gmail.com"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textStyle="bold"
android:fontFamily="@font/delius"
android:text="Enter Password:" />
<EditText
android:id="@+id/pass"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="1234" />
</TableRow>
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="172dp"
android:fontFamily="@font/amarante"
android:text="Login" />
</TableLayout>

MainActivity.java
package com.firstapp.practicle7;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText user, pass;
Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Que 2. Write a program to accept and display personal information of the student.

activity_accept_display.xml import android.widget.Button;


import android.widget.EditText;
<?xml version="1.0" encoding="utf-8"?> import android.widget.TextView;
<LinearLayout public class accept_display extends
xmlns:android="http://schemas.android.com/apk/res/ AppCompatActivity implements View.OnClickListener
android" {
xmlns:app="http://schemas.android.com/apk/res- private EditText name,email,pass;
auto" private Button button;
xmlns:tools="http://schemas.android.com/tools" private TextView textView;
android:layout_width="match_parent" @Override
android:layout_height="match_parent" protected void onCreate(Bundle
tools:context=".accept_display" savedInstanceState) {
android:orientation="vertical" super.onCreate(savedInstanceState);
android:background="@drawable/back">
<TextView setContentView(R.layout.activity_accept_display);
android:layout_width="wrap_content" name=(EditText)findViewById(R.id.name);
android:layout_height="wrap_content" email=(EditText)findViewById(R.id.email);
android:text="Enter All information" pass=(EditText)findViewById(R.id.enroll);
android:textSize="23dp" button=(Button)findViewById(R.id.button);
android:layout_marginTop="9dp" textView=(TextView)
android:fontFamily="@font/amarante" findViewById(R.id.textview);
android:layout_gravity="center"/> button.setOnClickListener(this);
<EditText }
android:id="@+id/name" @Override
android:layout_marginTop="20dp" public void onClick(View v) {
android:layout_width="match_parent" String name1=name.getText().toString();
android:layout_height="wrap_content" String email1=email.getText().toString();
android:textSize="20sp" String pass1=pass.getText().toString();
android:inputType="text" if (v.getId()==R.id.button){
android:maxLength="25"
android:hint="Name" textView.setText("Name="+name1+"\nEmail="+email1+"
android:textStyle="bold"/> \npass="+pass1);
<EditText }
android:id="@+id/email" }
android:layout_width="match_parent" }
android:layout_height="wrap_content"
android:textSize="20sp" Output
android:hint="Email"
android:layout_marginTop="5dp"
android:textStyle="bold"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/enroll"
android:inputType="numberDecimal"
android:maxLength="10"
android:hint="Enrollment"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginTop="5dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/branch"
android:inputType="text"
android:hint="Branch"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginTop="5dp"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="20sp"
android:layout_marginTop="15dp"
android:textAllCaps="false"
android:layout_gravity="center"/>
<TextView
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:textSize="23dp" />
</LinearLayout>

Accept_display.java
package com.firstapp.practicle7;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
Practical No. 8
Que 1.Write a program to create a first display screen of any search engine using Auto Complete Text View.
activity_main String[]
strings = {"One", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight " +
<?xml version="1.0" encoding="utf-8"?> "", "Nine", "Ten", "Eleven", "Twelve", "Thirteen",
<LinearLayout "Fourteen", "Fifteen"
xmlns:android="http://schemas.android.com/apk/res/android" , "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"};
xmlns:app="http://schemas.android.com/apk/res-auto" ArrayAdapter<String> adapter;
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" @Override
android:layout_height="match_parent" protected void onCreate(Bundle savedInstanceState) {
android:orientation="vertical" super.onCreate(savedInstanceState);
android:padding="16dp" setContentView(R.layout.activity_main);
tools:context=".MainActivity">
<ImageView autoCompleteTextView = findViewById(R.id.ac_text_view);
android:id="@+id/next_act" textView = findViewById(R.id.text_view);
android:layout_width="30dp" adapter = new ArrayAdapter<>(this,
android:layout_height="30dp" android.R.layout.simple_dropdown_item_1line, strings);
android:src="@drawable/next" autoCompleteTextView.setThreshold(1);
android:layout_gravity="right"/> autoCompleteTextView.setAdapter(adapter);
<AutoCompleteTextView autoCompleteTextView.setOnItemClickListener(new
android:layout_width="match_parent" AdapterView.OnItemClickListener() {
android:layout_height="wrap_content" @Override
android:id="@+id/ac_text_view" public void onItemClick(AdapterView<?> adapterView,
android:hint="Search...." View view, int i, long l) {
android:textSize="25dp" textView.setText(adapter.getItem(i));
android:padding="12dp" }
});
android:background="@android:drawable/editbox_background"/> next=findViewById(R.id.next_act);
<TextView next.setOnClickListener(new View.OnClickListener() {
android:layout_width="match_parent" @Override
android:layout_height="match_parent" public void onClick(View view) {
android:id="@+id/text_view" Intent intent=new Intent(MainActivity.this,dis_sem.class);
android:textSize="30sp" startActivity(intent);
android:textStyle="bold" finish();
android:fontFamily="monospace" }
android:textColor="@color/black" });
android:gravity="center" }
android:layout_marginTop="20dp"/> }
</LinearLayout>
Output
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.firstapp.practicle8">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Practicle8">
<activity android:name=".dis_sem"></activity>
<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>

MainActivity.java
package com.firstapp.practicle8;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
AutoCompleteTextView autoCompleteTextView;
ImageView next;
TextView textView;
Que 2.How to create AutoCompleteTextView field in XML?
activity_dis_sem.xml Output
<?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"
android:padding="16dp"
tools:context=".dis_sem">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ac_text_view"
android:hint="Search Your Subject"
android:textSize="25dp"
android:padding="12dp"

android:background="@android:drawable/editbox_background"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/text_view"
android:textSize="30sp"
android:textStyle="bold"
android:fontFamily="monospace"
android:textColor="@color/black"
android:gravity="center"
android:layout_marginTop="20dp"/>
</LinearLayout>

dis_sem.java

package com.firstapp.practicle8;

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.TextView;
public class dis_sem extends AppCompatActivity {
AutoCompleteTextView autoCompleteTextView;
TextView textView;
String[] strings = {"Mobile Application Development",
"Programming with Python", "Management",
"Network and Information Security", "ETI"};
ArrayAdapter<String> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dis_sem);
autoCompleteTextView = findViewById(R.id.ac_text_view);
textView = findViewById(R.id.text_view);
adapter = new ArrayAdapter<>(this,
android.R.layout.simple_dropdown_item_1line, strings);
autoCompleteTextView.setThreshold(1);
autoCompleteTextView.setAdapter(adapter);
autoCompleteTextView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView,

View view, int i, long l) {


textView.setText(adapter.getItem(i));
}
});
}
}
Practical No. 9
Que 1.Write a program to create a toggle button to display ON / OFF Bluetooth on the display screen.
activity_main.xml MainActivity.java

<?xml version="1.0" encoding="utf-8"?> package com.firstapp.practicle9;


<LinearLayout import android.bluetooth.BluetoothAdapter;
xmlns:android="http://schemas.android.com/apk/res/android" import android.content.Intent;
android:layout_width="match_parent"
android:layout_height="match_parent" import android.os.Bundle;
xmlns:app="http://schemas.android.com/apk/res-auto" import android.view.View;
android:paddingLeft="10dp" import android.widget.Button;
android:paddingRight="10dp" import android.widget.Toast;
android:orientation="vertical" import android.widget.ToggleButton;
android:gravity="center">
<TextView import androidx.appcompat.app.AppCompatActivity;
android:layout_width="wrap_content" public class MainActivity extends AppCompatActivity {
android:layout_height="wrap_content" @Override
android:text="Click toggle button to enable/disable bluetooth." protected void onCreate(Bundle savedInstanceState) {
android:gravity="center" super.onCreate(savedInstanceState);
android:textSize="18dp" setContentView(R.layout.activity_main);
android:fontFamily="@font/amaranth"/> ToggleButton toggleButton1 = (ToggleButton)
<ToggleButton findViewById(R.id.toggleButton);
android:id="@+id/toggleButton" final BluetoothAdapter bAdapter =
android:layout_width="wrap_content" BluetoothAdapter.getDefaultAdapter();
android:layout_height="wrap_content" toggleButton1.setOnClickListener(new View.OnClickListener() {
android:layout_marginLeft="6dp" @Override
android:layout_marginTop="20dp" public void onClick(View view) {
android:text="ToggleButton" if(toggleButton1.isChecked()){
android:textOff="Off" if(bAdapter == null)
android:textOn="On" {
app:layout_constraintStart_toStartOf="parent" Toast.makeText(getApplicationContext(),"Bluetooth Not
app:layout_constraintTop_toTopOf="parent" /> Supported",Toast.LENGTH_SHORT).show();
</LinearLayout> }
else{
Manifest.xml if(!bAdapter.isEnabled()){
startActivityForResult(new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),1);
<?xml version="1.0" encoding="utf-8"?> Toast.makeText(getApplicationContext(),"Bluetooth
<manifest Turned ON",Toast.LENGTH_SHORT).show();
xmlns:android="http://schemas.android.com/apk/res/ }
android" }
package="com.firstapp.practicle9"> }else{
<uses-permission bAdapter.disable();
android:name="android.permission.BLUETOOTH" /> Toast.makeText(getApplicationContext(),"Bluetooth Turned
<uses-permission
OFF", Toast.LENGTH_SHORT).show();
android:name="android.permission.BLUETOOTH_ADMIN"
/>
} }});
<uses-permission
}
android:name="android.permission.BLUETOOTH_CONNECT
}
" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher" output
android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Practicle9">
<activity android:name=".MainActivity">
</activity>
<activity
android:name=".calculator"
android:exported="true">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"

android:resource="@array/preloaded_fonts" />
</application>
</manifest>
Calculator.xml android:text="7"
android:textSize="30dp"
android:textStyle="bold"
<?xml version="1.0" encoding="utf-8"?> android:background="#181a14"
<LinearLayout android:textColor="#fff"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_weight="1"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_margin="1dp"/>
xmlns:tools="http://schemas.android.com/tools" <Button
android:layout_width="match_parent" android:onClick="digit"
android:layout_height="match_parent" android:id="@+id/eight"
tools:context=".MainActivity" android:layout_width="wrap_content"
android:orientation="vertical"> android:layout_height="match_parent"
<TextView android:text="8"
android:id="@+id/view" android:textSize="30dp"
android:layout_width="match_parent" android:textStyle="bold"
android:layout_height="60dp" android:background="#181a14"
android:gravity="right|center" android:textColor="#fff"
android:hint="0" android:layout_weight="1"
android:textSize="35dp"/> android:layout_margin="1dp"/>
<LinearLayout <Button
android:layout_width="match_parent" android:onClick="digit"
android:layout_height="220dp" android:id="@+id/nine"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_marginTop="350dp"> android:layout_height="match_parent"
<LinearLayout android:text="9"
android:layout_width="match_parent" android:textSize="30dp"
android:layout_height="wrap_content" android:textStyle="bold"
android:layout_weight="1"> android:background="#181a14"
<Button android:textColor="#fff"
android:onClick="clear" android:layout_weight="1"
android:id="@+id/clear" android:layout_margin="1dp"/>
android:layout_width="wrap_content" <Button
android:layout_height="match_parent" android:onClick="operator"
android:text="C" android:id="@+id/multiply"
android:textSize="30dp" android:layout_width="wrap_content"
android:textStyle="bold" android:layout_height="match_parent"
android:background="#181a14" android:text="×"
android:textColor="#fff" android:textSize="30dp"
android:layout_weight="1" android:textStyle="bold"
android:layout_margin="1dp"/> android:background="#a79300"
<Button android:textColor="#fff"
android:layout_width="wrap_content" android:layout_weight="1"
android:layout_height="match_parent" android:layout_margin="1dp"/>
android:text="+/-" </LinearLayout>
android:textSize="30dp" <LinearLayout
android:textStyle="bold" android:layout_width="match_parent"
android:background="#181a14" android:layout_height="wrap_content"
android:textColor="#fff" android:layout_weight="1">
android:layout_weight="1" <Button
android:layout_margin="1dp"/> android:onClick="digit"
<Button android:id="@+id/four"
android:id="@+id/percent" android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_height="match_parent" android:text="4"
android:text="%" android:textSize="30dp"
android:textSize="30dp" android:textStyle="bold"
android:textStyle="bold" android:background="#181a14"
android:background="#181a14" android:textColor="#fff"
android:textColor="#fff" android:layout_weight="1"
android:layout_weight="1" android:layout_margin="1dp"/>
android:layout_margin="1dp"/> <Button
<Button android:onClick="digit"
android:onClick="operator" android:id="@+id/five"
android:id="@+id/divide" android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_height="match_parent" android:text="5"
android:text="÷" android:textSize="30dp"
android:textSize="30dp" android:textStyle="bold"
android:textStyle="bold" android:background="#181a14"
android:background="#a79300" android:textColor="#fff"
android:textColor="#fff" android:layout_weight="1"
android:layout_weight="1" android:layout_margin="1dp"/>
android:layout_margin="1dp"/> <Button
</LinearLayout> android:onClick="digit"
<LinearLayout android:id="@+id/six"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1"> android:text="6"
<Button android:textSize="30dp"
android:onClick="digit" android:textStyle="bold"
android:id="@+id/seven" android:background="#181a14"
android:layout_width="wrap_content" android:textColor="#fff"
android:layout_height="match_parent" android:layout_weight="1"
android:layout_margin="1dp"/> <Button
<Button android:id="@+id/point"
android:onClick="operator" android:layout_width="wrap_content"
android:id="@+id/subtract" android:layout_height="match_parent"
android:layout_width="wrap_content" android:text="."
android:layout_height="match_parent" android:textSize="30dp"
android:text="−" android:textStyle="bold"
android:textSize="30dp" android:background="#181a14"
android:textStyle="bold" android:textColor="#fff"
android:background="#a79300" android:layout_weight="1"
android:textColor="#fff" android:layout_margin="1dp"/>
android:layout_weight="1" <Button
android:layout_margin="1dp"/> android:id="@+id/del"
</LinearLayout> android:layout_width="wrap_content"
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent" android:text="del"
android:layout_height="wrap_content" android:textSize="30dp"
android:layout_weight="1"> android:textStyle="bold"
<Button android:background="#181a14"
android:onClick="digit" android:textColor="#fff"
android:id="@+id/one" android:layout_weight="1"
android:layout_width="wrap_content" android:layout_margin="1dp"/>
android:layout_height="match_parent" <Button
android:text="1" android:onClick="operator"
android:textSize="30dp" android:id="@+id/equals"
android:textStyle="bold" android:layout_width="wrap_content"
android:background="#181a14" android:layout_height="match_parent"
android:textColor="#fff" android:text="="
android:layout_weight="1" android:textSize="30dp"
android:layout_margin="1dp"/> android:textStyle="bold"
<Button android:background="#236e22"
android:onClick="digit" android:textColor="#fff"
android:id="@+id/two" android:layout_weight="1"
android:layout_width="wrap_content" android:layout_margin="1dp"/>
android:layout_height="match_parent" </LinearLayout>
android:text="2" </LinearLayout>
android:textSize="30dp" </LinearLayout>
android:textStyle="bold"
android:background="#181a14" Calculator.java
android:textColor="#fff"
android:layout_weight="1"
android:layout_margin="1dp"/> package com.example.calculator;
<Button import androidx.appcompat.app.AppCompatActivity;
android:onClick="digit"
android:id="@+id/three" import android.os.Bundle;
android:layout_width="wrap_content" import android.view.View;
android:layout_height="match_parent" import android.widget.Button;
android:text="3" import android.widget.TextView;
android:textSize="30dp" public class MainActivity extends AppCompatActivity {
android:textStyle="bold" TextView text;
android:background="#181a14" Button btn;
android:textColor="#fff" double operand1, operand2, add = 0, subtract = 0, multiply = 0,
android:layout_weight="1" divide = 0, result = 0;
android:layout_margin="1dp"/> @Override
<Button protected void onCreate(Bundle savedInstanceState) {
android:onClick="operator" super.onCreate(savedInstanceState);
android:id="@+id/add" setContentView(R.layout.activity_main);
android:layout_width="wrap_content" }
android:layout_height="match_parent" public void digit(View view) {
android:text="+" text = (TextView)findViewById(R.id.view);
android:textSize="30dp" String currentText = text.getText().toString();
android:textStyle="bold" btn = (Button)view;
android:background="#a79300" String btnValue = btn.getText().toString();
android:textColor="#fff" if (currentText != "" && currentText.length() < 12)
android:layout_weight="1" {
android:layout_margin="1dp"/> if (Double.parseDouble(currentText) != 0)
</LinearLayout> {
<LinearLayout text.setText(currentText + btnValue);
android:layout_width="match_parent" }
android:layout_height="wrap_content" else
android:layout_weight="1"> {
<Button text.setText(btnValue);
android:onClick="digit" }
android:id="@+id/zero"
android:layout_width="wrap_content" }
android:layout_height="match_parent" else if(currentText.length() != 12)
android:text="0" {
android:textSize="30dp" text.setText(btnValue);
android:textStyle="bold" }
android:background="#181a14" }
android:textColor="#fff" public void clear(View view) {
android:layout_weight="1" operand1 = operand2 = add = subtract = multiply = divide = 0;
android:layout_margin="1dp"/> text = (TextView)findViewById(R.id.view);
text.setText(""); operand1 = operand2 = add = subtract = multiply = divide = 0;
} }
public void operator(View view) }
{ }
text = (TextView)findViewById(R.id.view);
String currentText = text.getText().toString();
output
if (currentText != "")
{
if (view.getId() == R.id.add)
{
if (add == 0)
{
operand1 = Double.parseDouble(currentText);
text.setText("");
add = 1;
}

if (view.getId() == R.id.subtract)
{
if (subtract == 0)
{
operand1 = Double.parseDouble(currentText);
text.setText("");
subtract = 1;
}

if (view.getId() == R.id.multiply)
{
if (multiply == 0)
{
operand1 = Double.parseDouble(currentText);
text.setText("");
multiply = 1;
}

if (view.getId() == R.id.divide)
{
if (divide == 0)
{
operand1 = Double.parseDouble(currentText);
text.setText("");
divide = 1;
}

}
}
if (view.getId() == R.id.equals && currentText != "")
{
if (add == 1)
{
operand2 = Double.parseDouble(currentText);
result = operand1 + operand2;
text.setText(result <=999999999999.0 ? String.format("%.2f",
result) : "Error");
}
else if (subtract == 1)
{
operand2 = Double.parseDouble(currentText);
result = operand1 - operand2;
text.setText(result <=999999999999.0 ? String.format("%.2f",
result) : "Error");
}
else if (multiply == 1)
{
operand2 = Double.parseDouble(currentText);
result = operand1 * operand2;
text.setText(result <=999999999999.0 ? String.format("%.2f",
result) : "Error");
}
else if (divide == 1)
{
operand2 = Double.parseDouble(currentText);
result = operand1 / operand2;
text.setText(result <=999999999999.0 ? String.format("%.2f",
result) : "Error");
}
Practical No. 10
Que 1. Write a program to create a login form for a social networking site.
Activity_main.xml android:textStyle="bold"
android:textColor="#9a9a9a"
<?xml version="1.0" encoding="utf-8"?> android:layout_marginStart="8dp"
<RelativeLayout android:layout_marginEnd="8dp"/>
xmlns:android="http://schemas.android.com/apk/res/android" <View
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="0dp"
xmlns:tools="http://schemas.android.com/tools" android:layout_height="1.5dp"
android:layout_width="match_parent" android:layout_weight="1"
android:layout_height="match_parent" android:background="#e2e2e2"/>
tools:context=".MainActivity"> </LinearLayout>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="English (India)" android:layout_marginTop="16dp"
android:textSize="14sp" android:gravity="center"
android:textColor="#c4c4c4" android:padding="4dp"
android:layout_marginTop="6dp" android:text="Log in with Facebook"
android:layout_centerHorizontal="true"/> android:textColor="#3897f0"
<LinearLayout android:textSize="15sp"
android:layout_width="match_parent" android:textStyle="bold"/>
android:layout_height="wrap_content" </LinearLayout>
android:orientation="vertical" <View
android:gravity="center" android:layout_width="match_parent"
android:paddingStart="28dp" android:layout_height="1.5dp"
android:paddingEnd="28dp" android:background="#e2e2e2"
android:layout_centerInParent="true"> android:layout_marginBottom="8dp"/>
<ImageView <TextView
android:layout_width="147dp" android:layout_width="match_parent"
android:layout_height="82dp" android:layout_height="wrap_content"
android:adjustViewBounds="true" android:id="@+id/sign_up"
android:src="@drawable/logo1" /> android:text="Sign up"
<EditText android:textSize="12sp"
android:layout_width="match_parent" android:textAlignment="center"
android:layout_height="wrap_content" android:layout_marginBottom="14dp"
android:textSize="14sp" android:layout_alignParentBottom="true"
android:gravity="center_horizontal" />
android:padding="12dp"
</RelativeLayout>
android:singleLine="true"
android:layout_marginTop="22dp"
android:hint="Phone number, email or username" Manifest.xml
android:background="@drawable/background_edit_text"/>
<EditText <?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent" <manifest
android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"
android:textSize="14sp" package="com.firstapp.practicle10">
android:padding="12dp" <application
android:singleLine="true" android:allowBackup="true"
android:inputType="numberPassword" android:icon="@mipmap/ic_launcher"
android:layout_marginTop="16dp" android:label="@string/app_name"
android:hint="Password" android:roundIcon="@mipmap/ic_launcher_round"
android:background="@drawable/background_edit_text" /> android:supportsRtl="true"
<Button android:theme="@style/Theme.Practicle10">
android:id="@+id/login" <activity android:name=".stud_login"></activity>
android:layout_width="match_parent" <activity
android:layout_height="wrap_content" android:name=".MainActivity"
android:text="Log In" android:exported="true">
android:textAllCaps="false" <intent-filter>
android:textColor="@color/white" <action android:name="android.intent.action.MAIN" />
android:padding="12dp" <category
android:layout_marginTop="18dp" android:name="android.intent.category.LAUNCHER" />
android:backgroundTint="#3897f0" </intent-filter>
app:cornerRadius="4dp"/> </activity>
<TextView <meta-data
android:layout_width="wrap_content" android:name="preloaded_fonts"
android:layout_height="wrap_content" android:resource="@array/preloaded_fonts" />
android:text="Forget password" </application>
android:textSize="12sp" </manifest>
android:layout_marginTop="8dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="12sp"
android:layout_gravity="center_vertical">
<View
android:layout_width="0dp"
android:layout_height="1.5dp"
android:layout_weight="1"
android:background="#e2e2e2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OR"
android:textSize="14sp"
Output
MainActivity.java

package com.firstapp.practicle10;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
button=findViewById(R.id.login);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(MainActivity.this,stud_login.class);
startActivity(intent);
finish();
Toast.makeText(MainActivity.this, "Login Successfull",
Toast.LENGTH_SHORT).show();
}});
}
}

background_edittext.xml

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


<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fafafa"/>
<stroke android:color="#e7e7e7"
android:width="1dp"/>
<corners android:radius="4dp"/>
</shape>
Que 2. Write a program to create a login form for student registration system
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
activity_stud_login.xml android:drawableLeft="@drawable/branch"
android:layout_centerHorizontal="true"
<?xml version="1.0" encoding="utf-8"?> android:layout_marginLeft="24dp"
<LinearLayout android:drawablePadding="12dp"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_marginTop="200dp"
xmlns:app="http://schemas.android.com/apk/res-auto" android:inputType="text"
xmlns:tools="http://schemas.android.com/tools" android:hint="Branch" />
android:layout_width="match_parent" <EditText
android:layout_height="match_parent" android:layout_width="250dp"
tools:context=".stud_login" android:layout_height="wrap_content"
android:orientation="vertical"> android:layout_alignParentTop="true"
<TextView android:layout_centerHorizontal="true"
android:layout_width="wrap_content" android:layout_marginLeft="24dp"
android:layout_height="wrap_content" android:drawablePadding="12dp"
android:layout_gravity="center" android:drawableLeft="@drawable/pass"
android:layout_marginTop="24dp" android:layout_marginTop="250dp"
android:fontFamily="@font/cormorant_garamond_medium" android:inputType="numberPassword"
android:text="Government polytechnic Murtizapur" android:hint="Password" />
android:textSize="23dp" <Button
android:textStyle="bold" /> android:id="@+id/regis"
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="320dp"
android:layout_gravity="center" android:gravity="center"
android:fontFamily="@font/caladea" android:layout_marginBottom="12dp"
android:layout_marginTop="30dp" android:layout_marginLeft="105dp"
android:text="Register Student" android:hint="Register"
android:textSize="23dp"
android:textStyle="bold"/> android:backgroundTint="@color/teal_200"
<androidx.cardview.widget.CardView android:textColor="@color/white"
android:layout_width="300dp" android:textStyle="bold"
android:layout_height="wrap_content" android:fontFamily="cursive"/>
android:layout_marginTop="30dp" </androidx.cardview.widget.CardView>
android:layout_gravity="center" </LinearLayout>
app:cardElevation="12dp"
app:cardCornerRadius="23dp">
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="24dp"
android:hint="Name"
android:drawablePadding="12dp"
android:drawableLeft="@drawable/name"
android:inputType="text" />
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="24dp"
android:drawableLeft="@drawable/enroll"
android:layout_marginTop="50dp"
android:drawablePadding="12dp"
android:inputType="number"
android:hint="Enrollment no" />
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:drawableLeft="@drawable/roll"
android:layout_centerHorizontal="true"
android:layout_marginLeft="24dp"
android:layout_marginTop="100dp"
android:inputType="number"
android:drawablePadding="12dp"
android:hint="Roll no" />
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:drawableLeft="@drawable/mob"
android:layout_centerHorizontal="true"
android:layout_marginLeft="24dp"
android:layout_marginTop="150dp"
android:inputType="number"
android:drawablePadding="12dp"
android:hint="Mobile no" />
<EditText
android:layout_width="250dp"
Stud_login.java Output

package com.firstapp.practicle10;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class stud_login extends AppCompatActivity {

Button register;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stud_login);

getSupportActionBar().hide();
register=findViewById(R.id.regis);
register.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
Toast.makeText(stud_login.this, "Registration Successfull!!",
Toast.LENGTH_SHORT).show();
}
}
);
}
}
Practical No. 11

activity_main.xml android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
<?xml version="1.0" encoding="utf-8"?> android:supportsRtl="true"
<androidx.appcompat.widget.LinearLayoutCompat android:theme="@style/Theme.Practicle11">
<activity android:name=".MainActivity"
xmlns:android="http://schemas.android.com/apk/res/android"
android:exported="true">
xmlns:app="http://schemas.android.com/apk/res-auto"
<intent-filter>
xmlns:tools="http://schemas.android.com/tools" <action android:name="android.intent.action.MAIN" />
android:layout_width="match_parent" <category
android:layout_height="match_parent" android:name="android.intent.category.LAUNCHER" />
tools:context=".MainActivity" </intent-filter>
android:orientation="vertical"> </activity>
<androidx.cardview.widget.CardView <meta-data
android:layout_width="300dp" android:name="preloaded_fonts"
android:layout_height="350dp" android:resource="@array/preloaded_fonts" />
android:layout_gravity="center" </application>
app:cardElevation="12dp" </manifest>
app:cardCornerRadius="23dp"
android:layout_marginTop="144dp" MainActivity.java
android:outlineSpotShadowColor="@color/orange"> package com.firstapp.practicle11;
<TextView import androidx.appcompat.app.AppCompatActivity;
android:layout_width="wrap_content" import android.os.Bundle;
android:layout_height="wrap_content" import android.view.View;
import android.widget.Button;
android:text="Select your favourite programming language"
import android.widget.CheckBox;
android:fontFamily="@font/bilbo_swash_caps" import android.widget.Toast;
android:layout_marginLeft="12dp" import java.util.HashMap;
android:textSize="23dp" public class MainActivity extends AppCompatActivity {
android:layout_marginTop="12dp"/> CheckBox java,python,c,cpp,and;Button check;
<CheckBox @Override
android:id="@+id/java" protected void onCreate(Bundle savedInstanceState) {
android:layout_width="wrap_content" super.onCreate(savedInstanceState);
android:layout_height="wrap_content" setContentView(R.layout.activity_main);
android:layout_marginTop="50dp" java=findViewById(R.id.java);
android:text="java"/> python=findViewById(R.id.python);
<CheckBox c=findViewById(R.id.c);
cpp=findViewById(R.id.cpp);
android:id="@+id/cpp"
and=findViewById(R.id.android);
android:layout_width="wrap_content"
check=findViewById(R.id.check);
android:layout_height="wrap_content" check.setOnClickListener(new View.OnClickListener() {
android:layout_marginTop="100dp" @Override
android:text="C++"/> public void onClick(View view) {
<CheckBox if(java.isChecked()){
android:id="@+id/c" Toast.makeText(MainActivity.this, "Java is checked",
android:layout_width="wrap_content" Toast.LENGTH_SHORT).show();
android:layout_height="wrap_content" }if(c.isChecked()){
android:layout_marginTop="150dp" Toast.makeText(MainActivity.this, "C is checked",
android:text="C"/> Toast.LENGTH_SHORT).show();
<CheckBox }if(cpp.isChecked()){
android:id="@+id/python" Toast.makeText(MainActivity.this, "C++ is checked",
Toast.LENGTH_SHORT).show();
android:layout_width="wrap_content"
}if(python.isChecked()){
android:layout_height="wrap_content"
Toast.makeText(MainActivity.this, "Python is checked",
android:layout_marginTop="200dp" Toast.LENGTH_SHORT).show();
android:text="Python"/> }if(and.isChecked()){
<CheckBox Toast.makeText(MainActivity.this, "Android is checked",
android:id="@+id/android" Toast.LENGTH_SHORT).show();
android:layout_width="wrap_content" }
android:layout_height="wrap_content" }});
android:layout_marginTop="250dp" }
android:text="Android"/> }
<Button
android:id="@+id/check" output
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:layout_marginLeft="110dp"
android:hint="Check"
android:backgroundTint="@color/blue"/>
</androidx.cardview.widget.CardView>
</androidx.appcompat.widget.LinearLayoutCompat>

Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.firstapp.practicle11">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Practical No. 12
Que 1 . Write a program to show the following ouput. First 2 radio button are without using radio group and next 2 radio
button are using radio group android:textSize="20dp" />
activity_main.xml </RadioGroup>
<?xml version="1.0" encoding="utf-8"?> <Button
<LinearLayout android:layout_width="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/ android:layout_height="wrap_content"
android" android:text="Show Selected"
xmlns:tools="http://schemas.android.com/tools" android:layout_marginTop="270dp"
android:layout_width="match_parent" android:id="@+id/button"
android:layout_height="match_parent" android:onClick="onclickbuttonMethod"
xmlns:app="http://schemas.android.com/apk/res-
auto" android:layout_gravity="center_horizontal" />
android:orientation="vertical" </androidx.cardview.widget.CardView>
tools:context=".MainActivity"> </LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="300dp"
android:layout_height="350dp" Manifest.xml
android:layout_gravity="center"
app:cardElevation="212dp" <?xml version="1.0" encoding="utf-8"?>
app:cardCornerRadius="23dp" <manifest
android:layout_marginTop="144dp"
xmlns:android=http://schemas.android.com/apk/res/android
android:outlineSpotShadowColor="@color/blue">
<TextView package="com.firstapp.practicle12">
android:id="@+id/textView1" <application
android:layout_width="fill_parent" android:allowBackup="true"
android:layout_height="wrap_content" android:icon="@mipmap/ic_launcher"
android:layout_marginTop="12dp" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:fontFamily="@font/bilbo_swash_caps" android:supportsRtl="true"
android:gravity="center_horizontal" android:theme="@style/Theme.Practicle12">
android:text="Select Semester" <activity android:name=".MainActivity"
android:textSize="22dp" /> android:exported="true">
<RadioButton <intent-filter>
android:id="@+id/radioButton1" <action android:name="android.intent.action.MAIN" />
android:layout_width="fill_parent"
android:layout_height="wrap_content" <category
android:name="android.intent.category.LAUNCHER" />
android:layout_gravity="center_horizontal" </intent-filter>
android:text="5th semester" </activity>
android:layout_marginTop="30dp" <meta-data
android:textSize="20dp" /> android:name="preloaded_fonts"
<RadioButton android:resource="@array/preloaded_fonts" />
android:id="@+id/radioButton2"
</application>
android:layout_width="fill_parent"
</manifest>
android:layout_height="wrap_content"
android:text="6th semester"
android:layout_marginTop="90dp"
android:textSize="20dp" />
<View
android:layout_width="200dp"
android:layout_height="1dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="140dp"
android:background="#B8B894" />
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"

android:fontFamily="@font/bilbo_swash_caps"
android:gravity="center_horizontal"
android:textSize="22dp"
android:text="Select Gender" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioGroup">
<RadioButton
android:id="@+id/radioMale"
android:layout_width="fill_parent"

android:layout_height="wrap_content"
android:text=" Male"
android:layout_marginTop="170dp"
android:checked="false"
android:textSize="20dp" />
<RadioButton
android:id="@+id/radioFemale"
android:layout_width="fill_parent"

android:layout_height="wrap_content"
android:checked="false"
android:text=" Female"
MainActivity.java Output

package com.firstapp.practicle12;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

Button button;
RadioButton genderradioButton,r1,r2;
RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioGroup=(RadioGroup)findViewById(R.id.radioGroup);
r1=findViewById(R.id.radioButton1);
r2=findViewById(R.id.radioButton2);
}

public void onclickbuttonMethod(View v){


int selectedId = radioGroup.getCheckedRadioButtonId();
genderradioButton = (RadioButton) findViewById(selectedId);
if(selectedId==-1){
Toast.makeText(MainActivity.this,"Nothing selected",
Toast.LENGTH_SHORT).show();
}if(r1.isChecked()==true){
Toast.makeText(this, "5th semester was clicked",
Toast.LENGTH_SHORT).show();
}
if(r2.isChecked()==true){
Toast.makeText(this, "6th semester was clicked",
Toast.LENGTH_SHORT).show();
}
Toast.makeText(MainActivity.this,genderradioButton.getText(),
Toast.LENGTH_SHORT).show();
}
}
Practical No. 13
Que 1.Write a program to display circular progress bar
activity_main.xml </activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
<?xml version="1.0" encoding="utf-8"?> </manifest>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" circle_shape.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" <?xml version="1.0" encoding="utf-8"?>
android:layout_height="match_parent"
tools:context=".MainActivity" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"> android:shape="ring"
<ImageView android:innerRadiusRatio="2.5"
android:id="@+id/next_que" android:thickness="12dp"
android:layout_width="40dp" android:useLevel="false">
android:layout_height="40dp" <solid android:color="#6C6969"/>
android:src="@drawable/next"
android:layout_gravity="right"/> </shape>
<FrameLayout
android:layout_width="200dp"
android:layout_height="200dp" circular_progressbar.xml
android:layout_marginTop="123dp"
android:layout_gravity="center">
<ProgressBar <?xml version="1.0" encoding="utf-8"?>
android:id="@+id/cir_pro" <rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:fromDegrees="270"
android:layout_height="match_parent" android:toDegrees="270"
style="@style/Widget.AppCompat.ProgressBar.Horizontal" >
android:layout_gravity="center" <shape android:innerRadiusRatio="2.5"
android:indeterminate="false" android:shape="ring"
android:background="@drawable/circle_shape" android:thickness="10dp"
android:progressDrawable="@drawable/circular_progressbar" android:useLevel="true">
android:progress="0"/> <gradient
<TextView android:angle="0"
android:id="@+id/status" android:startColor="#0097A7"
android:layout_width="wrap_content" android:endColor="#303F9F"
android:layout_height="wrap_content" android:type="sweep"
android:textSize="40sp" android:useLevel="false"/>
android:textStyle="bold" </shape>
android:text="50%"
android:textAlignment="center" </rotate>
android:layout_gravity="center"
android:textColor="#FF0000"/>
</FrameLayout>
<Button
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click to start"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:textAlignment="center"
android:textSize="25sp"/>
</LinearLayout>

Manifest.xml

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


<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.firstapp.practical13" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Practical13" >
<activity android:name=".horizantal_prog"
android:exported="true" >
</activity>
<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>
MainActivity.xml Output

package com.firstapp.practical13;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


ProgressBar cir_pro;
Button click;
TextView status;
int progressStatus=0;
Handler handler=new Handler();
ImageView next;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
cir_pro=findViewById(R.id.cir_pro);
click=findViewById(R.id.progress);
status=findViewById(R.id.status);
next=findViewById(R.id.next_que);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new
Intent(MainActivity.this,horizantal_prog.class);
startActivity(intent);
finish();
}
});
click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
public void run() {
while (progressStatus<100){
progressStatus+=1;
handler.post(new Runnable() {
@Override
public void run() {
cir_pro.setProgress(progressStatus);
status.setText(progressStatus+"%");
}
});
try {
Thread.sleep(200);
}catch (InterruptedException e){
e.printStackTrace();
}
}
}
}).start();
}
});
}
}
Que 2. Write a program to show the following output
activity_horizantal_prog.xml }
});
}
<?xml version="1.0" encoding="utf-8"?> if (progressBarStatus >= 100) {
<RelativeLayout try {
xmlns:android="http://schemas.android.com/apk/res/android" Thread.sleep(1000);
xmlns:tools="http://schemas.android.com/tools" } catch (InterruptedException e) {
xmlns:app="http://schemas.android.com/apk/res-auto" e.printStackTrace();
android:layout_width="match_parent" }
android:layout_height="match_parent" progressBar.dismiss();
tools:context=".horizantal_prog" }
android:gravity="center"> }
<TextView }).start();
android:layout_width="wrap_content" }
android:layout_height="wrap_content" });
android:layout_marginTop="70dp" }
android:fontFamily="@font/crushed" public int doOperation() {
android:textSize="23dp" while (fileSize <= 10000) {
android:text="Click here to download a file" /> fileSize++;
<Button if (fileSize == 1000) {
android:id="@+id/button1" return 10;
android:layout_width="wrap_content" } else if (fileSize == 2000) {
android:layout_height="wrap_content" return 20;
android:layout_alignParentTop="true" } else if (fileSize == 3000) {
android:layout_marginTop="100dp" return 30;
android:layout_marginLeft="40dp" } else if (fileSize == 4000) {
android:text="download file" /> return 40;
</RelativeLayout> }
return 100;
}
horizantal_prog.java }

package com.firstapp.practical13; Output


import android.app.ProgressDialog;
import android.os.Handler;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class horizantal_prog extends AppCompatActivity {


Button btnStartProgress;
ProgressDialog progressBar;
private int progressBarStatus = 0;
private Handler progressBarHandler = new Handler();
private long fileSize = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_horizantal_prog);
addListenerOnButtonClick();
getSupportActionBar().hide();
}
public void addListenerOnButtonClick() {
btnStartProgress = findViewById(R.id.button1);
btnStartProgress.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
progressBar = new ProgressDialog(v.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("File downloading ...");

progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
progressBarStatus = 0;
fileSize = 0;
new Thread(new Runnable() {
public void run() {
while (progressBarStatus < 100) {
progressBarStatus = doOperation();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);
Practical No. 14
Que 1. Write a program to show the following output
activity_main.xml Manifest.xml

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


<?xml version="1.0" encoding="utf-8"?> <manifest
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android" package="com.firstapp.practical14">
xmlns:app="http://schemas.android.com/apk/res-auto" <application
xmlns:tools="http://schemas.android.com/tools" android:allowBackup="true"
android:layout_width="match_parent" android:icon="@mipmap/ic_launcher"
android:layout_height="match_parent" android:label="@string/app_name"
tools:context=".MainActivity" android:roundIcon="@mipmap/ic_launcher_round"
android:orientation="vertical"> android:supportsRtl="true"
<ImageView android:theme="@style/Theme.Practical14">
android:id="@+id/next" <activity android:name=".Q4_text_usingvertical"></activity>
android:layout_width="30dp" <activity
android:layout_height="30dp" android:name=".Q3_15_button"
android:src="@drawable/next" android:exported="true">
android:layout_gravity="right"/> </activity>
<ListView <activity
android:id="@+id/list" android:name=".Q2_changeimage"
android:layout_width="match_parent" android:exported="true" />
android:layout_height="match_parent" /> <activity
</LinearLayout> android:name=".MainActivity"
android:exported="true">
MainActivity.java <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
package com.firstapp.practical14;
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
import androidx.appcompat.app.AppCompatActivity;
</activity>
<meta-data
import android.content.Intent;
android:name="preloaded_fonts"
import android.os.Bundle;
android:resource="@array/preloaded_fonts" />
import android.view.View;
</application>
import android.widget.AdapterView;
</manifest>
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView; Output
public class MainActivity extends AppCompatActivity {
ImageView next;
ListView l;
String tutorials[]
= { "Java","cpp","c","Python","Android","Ruby"
,"SQL","Fortron","Ajax","HTML","CSS","Tailwind
css","Javascript"};
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
next=findViewById(R.id.next);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new
Intent(MainActivity.this,Q2_changeimage.class);
startActivity(intent);
finish();
}
});

l = findViewById(R.id.list);
ArrayAdapter<String> arr;
arr = new ArrayAdapter<String>(this,
R.layout.support_simple_spinner_dropdown_item, tutorials);
l.setAdapter(arr);
}
}
Que 2. Write a program to display an image using Image view and a button named as "change Image" once u click on
button another image should get displayed.
activity_q2_changeimage.xml });
btn.setOnClickListener(new View.OnClickListener() {
@Override
<?xml version="1.0" encoding="utf-8"?> public void onClick(View view) {
<LinearLayout imageView.setImageResource(R.drawable.sec);
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=".Q2_changeimage"
android:orientation="vertical">
Output
<ImageView
android:id="@+id/next"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/next"
android:layout_gravity="right"/>
<androidx.cardview.widget.CardView
android:layout_width="300dp"
android:layout_height="300dp"
app:cardElevation="12dp"
app:cardCornerRadius="23dp"
android:layout_gravity="center"
android:layout_marginTop="144dp"
android:outlineSpotShadowColor="@color/orange">
android:elevation="40dp"
android:outlineSpotShadowColor="@color/orange">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/image"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginLeft="75dp"
android:layout_marginTop="50dp"
android:src="@drawable/first"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="12dp"
android:textSize="17dp"
android:fontFamily="@font/crushed"
android:text="Click the change button to change the image"/>
<Button
android:id="@+id/change"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="103dp"
android:layout_marginTop="210dp"
android:text="change" />
</androidx.cardview.widget.CardView>
</LinearLayout>

Q2_changeimage.java

package com.firstapp.practical14;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class Q2_changeimage extends AppCompatActivity {
ImageView next;
ImageView imageView;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_q2_changeimage);
getSupportActionBar().hide();
imageView=findViewById(R.id.image);
btn=findViewById(R.id.change);
next=findViewById(R.id.next);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new
Intent(Q2_changeimage.this,Q3_15_button.class);
startActivity(intent);
finish();
}
Que 3. Write a program to display 15 button using grid view
activity_q315_button.xml });
gridview = findViewById(R.id.gridview);
for (int i = 0; i < 15; i++) {
<?xml version="1.0" encoding="utf-8"?> arr[i] = Integer.toString(i + 1);
<LinearLayout }
xmlns:android="http://schemas.android.com/apk/res/android" ArrayAdapter<String> ad = new ArrayAdapter<String>(this,
xmlns:app="http://schemas.android.com/apk/res-auto" R.layout.activity_listview, R.id.btn, arr);
xmlns:tools="http://schemas.android.com/tools" gridview.setAdapter(ad);
android:layout_width="match_parent" }
android:layout_height="match_parent" }
tools:context=".Q3_15_button"
android:orientation="vertical">
<ImageView
Output
android:id="@+id/next"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/next"
android:layout_gravity="right"/>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:layout_marginTop="30dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"
tools:context=".MainActivity"></GridView>
</LinearLayout>

activity_listview.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:orientation="vertical">
<Button
android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>

Q3_15_button.java

package com.firstapp.practical14;

import android.content.Intent;
import android.os.Bundle;

import android.view.View;
import android.widget.ArrayAdapter;

import android.widget.GridView;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;
public class Q3_15_button extends AppCompatActivity {
ImageView next;
GridView gridview;
String arr[] = new String[15];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_q315_button);
getSupportActionBar().hide();
next=findViewById(R.id.next);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new
Intent(Q3_15_button.this,Q4_text_usingvertical.class);
startActivity(intent);
finish();
}
Que 4. Write a program to display a textview using vertical scroll view
activity_q4_text_usingvertical.xml Output

<?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=".Q4_text_usingvertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="34dp"
android:textStyle="bold"
android:fontFamily="@font/comic_neue_light"
android:text="What is Machine Learning"
android:textSize="25dp"
android:layout_marginTop="12dp"/>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="@font/titillium_web_light"
android:text="Machine learning (ML) is the study of computer
algorithms that can improve automatically through experience and by
the use of data.It is seen as a part of artificial intelligence. Machine
learning algorithms build a model based on sample data, known as
training data, in order to make predictions or decisions without being
explicitly programmed to do so. Machine learning algorithms are used
in a wide variety of applications, such as in medicine, email filtering,
speech recognition, and computer vision, where it is difficult or
unfeasible to develop conventional algorithms to perform the needed
tasks.

A subset of machine learning is closely related to computational


statistics, which focuses on making predictions using computers; but
not all machine learning is statistical learning. The study of
mathematical optimization delivers methods, theory and application
domains to the field of machine learning. Data mining is a related field
of study, focusing on exploratory data analysis through unsupervised
learning. Some implementations of machine learning use data and
neural networks in a way that mimics the working of a biological
brain.[7][8] In its application across business problems, machine
learning is also referred to as predictive analytics."
android:textSize="20dp" />
</ScrollView>
</RelativeLayout>

Q4_text_usingvertical.java

package com.firstapp.practical14;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
public class Q4_text_usingvertical extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_q4_text_usingvertical);
getSupportActionBar().hide();
}
}
Practical No 15
Que 1. Write a program to display following toast message
activity_main.xml android:textStyle="bold"
android:textSize="15dp" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" MainActivity.java
android:layout_width="match_parent" package com.firstapp.practicle15;
android:layout_height="match_parent" import android.content.Intent;
xmlns:tools="http://schemas.android.com/tools" import android.os.Bundle;
android:orientation="vertical" import android.view.Gravity;
tools:context=".MainActivity"> import android.view.LayoutInflater;
<ImageView import android.view.View;
android:id="@+id/next" import android.view.ViewGroup;
android:layout_width="30dp" import android.widget.Button;
android:layout_height="30dp" import android.widget.ImageView;
android:src="@drawable/next" import android.widget.TextView;
android:layout_gravity="right"/> import android.widget.Toast;
<TextView
android:layout_width="wrap_content" import androidx.appcompat.app.AppCompatActivity;
android:layout_height="wrap_content" public class MainActivity extends AppCompatActivity {
android:fontFamily="@font/bubblegum_sans" ImageView next;
android:layout_marginTop="234dp" @Override
android:layout_marginLeft="30dp" protected void onCreate(Bundle savedInstanceState) {
android:textSize="20dp" super.onCreate(savedInstanceState);
android:text="Click below button to display toast message" /> setContentView(R.layout.activity_main);
<Button getSupportActionBar().hide();
android:id="@+id/btnShow" Button btn = (Button)findViewById(R.id.btnShow);
android:layout_width="wrap_content" next=findViewById(R.id.next);
android:layout_height="wrap_content" next.setOnClickListener(new View.OnClickListener() {
android:layout_marginTop="12dp" @Override
android:layout_marginLeft="80dp" public void onClick(View view) {
android:text="Show Custom Toast"/> Intent intent=new Intent(MainActivity.this,Q2_order.class);
</LinearLayout> startActivity(intent);
finish();
Manifest.xml }
});
<?xml version="1.0" encoding="utf-8"?> btn.setOnClickListener(new View.OnClickListener() {
<manifest @Override
xmlns:android="http://schemas.android.com/apk/res/android" public void onClick(View v) {
package="com.firstapp.practicle15"> LayoutInflater inflater = getLayoutInflater();
<application View layout = inflater.inflate(R.layout.custom_toast,
android:allowBackup="true" (ViewGroup) findViewById(R.id.custom_toast_layout));
android:icon="@mipmap/ic_launcher" TextView tv = (TextView) layout.findViewById(R.id.txtvw);
android:label="@string/app_name" tv.setText("Have a nice day :)");
android:roundIcon="@mipmap/ic_launcher_round" Toast toast = new Toast(getApplicationContext());
android:supportsRtl="true" toast.setGravity(Gravity.CENTER_VERTICAL, 0, 400);
android:theme="@style/Theme.Practicle15"> toast.setDuration(Toast.LENGTH_LONG);
<activity android:name=".Q2_order"></activity> toast.setView(layout);
<activity toast.show();
android:name=".MainActivity" }
android:exported="true"> });
<intent-filter> }
<action android:name="android.intent.action.MAIN" /> }
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Output
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
</manifest>

custom_toast.xml

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


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_toast_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="@color/orange"
android:gravity="center">
<TextView android:id="@+id/txtvw"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_marginLeft="22dp"
android:layout_marginTop="2dp"
android:textColor="#FFF"
activity_q2_order.xml android:orientation="horizontal">
<CheckBox
android:id="@+id/checkBox7"
<?xml version="1.0" encoding="utf-8"?> android:layout_width="wrap_content"
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="match_parent" android:layout_marginTop="190dp"
tools:context=".Q2_order" android:text="Kurkure"
android:orientation="vertical" />
android:gravity="center"> <CheckBox
<androidx.cardview.widget.CardView android:id="@+id/checkBox8"
android:layout_width="300dp" android:layout_width="wrap_content"
android:layout_height="300dp" android:layout_height="wrap_content"
app:cardElevation="12dp" android:layout_marginLeft="75dp"
app:cardCornerRadius="23dp" android:layout_marginTop="190dp"
android:outlineSpotShadowColor="@color/orange"> android:text="Chips" />
android:elevation="40dp" </LinearLayout>
android:outlineSpotShadowColor="@color/orange"> <Button android:id="@+id/button"
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="100dp"
android:layout_marginLeft="12dp" android:layout_marginTop="250dp"
android:layout_marginTop="12dp" android:text="Order"/>
android:fontFamily="@font/alegreya_sans_sc" </androidx.cardview.widget.CardView>
android:text="Select items to order!!" </LinearLayout>
android:textSize="23dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pizza"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="40dp"/>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="90dp"
android:layout_marginTop="40dp"
android:text="Coffee"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:text="Burger" />
<CheckBox
android:id="@+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="82dp"
android:layout_marginTop="90dp"
android:text="Sandwich" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="140dp"
android:text="Samosa" />
<CheckBox
android:id="@+id/checkBox6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="72dp"
android:layout_marginTop="140dp"
android:text="Kachori" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Q2_order.java Output

package com.firstapp.practicle15;

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 Q2_order extends AppCompatActivity {


CheckBox pizza, coffe, burger,sand,samosa,kachori,kur,chips;
Button buttonOrder;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_q2_order);
addListenerOnButtonClick();
getSupportActionBar().hide();
}
public void addListenerOnButtonClick() {
pizza = (CheckBox) findViewById(R.id.checkBox);
coffe = (CheckBox) findViewById(R.id.checkBox2);
burger = (CheckBox) findViewById(R.id.checkBox3);
sand = (CheckBox) findViewById(R.id.checkBox4);
samosa = (CheckBox) findViewById(R.id.checkBox5);
kachori = (CheckBox) findViewById(R.id.checkBox6);
kur = (CheckBox) findViewById(R.id.checkBox7);
chips = (CheckBox) findViewById(R.id.checkBox8);
buttonOrder = (Button) findViewById(R.id.button);
buttonOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int totalamount = 0;
StringBuilder result = new StringBuilder();
result.append("Selected Items:");
if (pizza.isChecked()) {
result.append("\nPizza 100Rs");
totalamount += 100;
}
if (coffe.isChecked()) {
result.append("\nCoffe 50Rs");
totalamount += 50;
}
if (burger.isChecked()) {
result.append("\nBurger 120Rs");
totalamount += 120;
}
if (sand.isChecked()) {
result.append("\nSandwich 100Rs");
totalamount += 100;
}
if (samosa.isChecked()) {
result.append("\nSamosa 12Rs");
totalamount += 12;
}
if (kachori.isChecked()) {
result.append("\nKachori 10Rs");
totalamount += 10;
}
if (kur.isChecked()) {
result.append("\nKurkure 10Rs");
totalamount += 10;
}
if (chips.isChecked()) {
result.append("\nChips 10Rs");
totalamount += 10;
}
result.append("\nTotal: " + totalamount + "Rs");
Toast.makeText(getApplicationContext(), result.toString(),
Toast.LENGTH_LONG).show();
}

});
}
}
Practical No. 16
Que 1. Write a prog to display following output. Use Timepicker and Spinnermode
activity_main.xml finish();
}
});
<?xml version="1.0" encoding="utf-8"?> tvw=(TextView)findViewById(R.id.textView1);
<LinearLayout picker=(TimePicker)findViewById(R.id.timePicker1);
xmlns:android="http://schemas.android.com/apk/res/android" picker.setIs24HourView(true);
android:layout_width="match_parent" btnGet=(Button)findViewById(R.id.button1);
android:layout_height="match_parent" btnGet.setOnClickListener(new View.OnClickListener() {
xmlns:tools="http://schemas.android.com/tools" @Override
xmlns:app="http://schemas.android.com/apk/res-auto" public void onClick(View v) {
tools:context=".MainActivity" int hour, minute;
android:orientation="vertical"> String am_pm;
<ImageView if (Build.VERSION.SDK_INT >= 23 ){
android:id="@+id/next" hour = picker.getHour();
android:layout_width="30dp" minute = picker.getMinute();
android:layout_height="30dp" }
android:src="@drawable/next" else{
android:layout_gravity="right"/> hour = picker.getCurrentHour();
<androidx.cardview.widget.CardView minute = picker.getCurrentMinute();
android:layout_width="300dp" }
android:layout_height="500dp" if(hour > 12) {
app:cardElevation="11dp" am_pm = "PM";
android:layout_marginLeft="29dp" hour = hour - 12;
android:layout_marginTop="60dp" }
app:cardCornerRadius="12dp" else{
android:outlineSpotShadowColor="@color/orange"> am_pm="AM";
<TimePicker }
android:id="@+id/timePicker1" tvw.setText("Selected Time: "+ hour +":"+ minute+"
android:layout_width="wrap_content" "+am_pm);
android:layout_height="wrap_content" }
android:layout_centerHorizontal="true" });
android:layout_marginTop="20dp"/> }
<Button }
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" Output
android:layout_below="@+id/timePicker1"
android:layout_marginTop="410dp"
android:text="Get Time"
android:layout_marginLeft="100dp"/>

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_marginLeft="80dp"
android:layout_marginTop="460dp"
android:fontFamily="@font/crushed"
android:textSize="18dp"
android:textStyle="bold" />
</androidx.cardview.widget.CardView>

</LinearLayout>

MainActivity.java
package com.firstapp.practical16;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.TimePicker;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
TimePicker picker;
Button btnGet;
TextView tvw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView next = findViewById(R.id.next);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(MainActivity.this,question_2.class);
startActivity(intent);
Que 2. Write a prog to display following output

activity_question2.xml import android.widget.DatePicker;


import android.widget.EditText;
import android.widget.TimePicker;
<?xml version="1.0" encoding="utf-8"?> import androidx.appcompat.app.AppCompatActivity;
<RelativeLayout import java.util.Calendar;
xmlns:android="http://schemas.android.com/apk/res/android" public class question_2 extends AppCompatActivity implements
android:layout_width="match_parent" View.OnClickListener {
android:layout_height="match_parent" Button btnDatePicker, btnTimePicker;
android:gravity="center">
<EditText EditText txtDate, txtTime;
android:layout_width="200dp" private int mYear, mMonth, mDay, mHour, mMinute;
android:layout_height="wrap_content" @Override
android:id="@+id/in_date" protected void onCreate(Bundle savedInstanceState) {
android:layout_marginTop="82dp" super.onCreate(savedInstanceState);
android:layout_alignParentTop="true" setContentView(R.layout.activity_question2);
android:layout_alignParentLeft="true" btnDatePicker=(Button)findViewById(R.id.btn_date);
android:layout_alignParentStart="true" /> btnTimePicker=(Button)findViewById(R.id.btn_time);
<Button txtDate=(EditText)findViewById(R.id.in_date);
android:layout_width="wrap_content" txtTime=(EditText)findViewById(R.id.in_time);
android:layout_height="wrap_content" btnDatePicker.setOnClickListener(this);
android:text="SELECT DATE" btnTimePicker.setOnClickListener(this);
android:id="@+id/btn_date" }
android:layout_alignBottom="@+id/in_date" @Override
android:layout_toRightOf="@+id/in_date" public void onClick(View v) {
android:layout_toEndOf="@+id/in_date" /> if (v == btnDatePicker) {
<EditText final Calendar c = Calendar.getInstance();
android:layout_width="200dp" mYear = c.get(Calendar.YEAR);
android:layout_height="wrap_content" mMonth = c.get(Calendar.MONTH);
android:id="@+id/in_time" mDay = c.get(Calendar.DAY_OF_MONTH);
android:layout_below="@+id/in_date" DatePickerDialog datePickerDialog = new
android:layout_alignParentLeft="true" DatePickerDialog(this,
android:layout_alignParentStart="true" /> new DatePickerDialog.OnDateSetListener() {
<Button @Override
android:layout_width="wrap_content" public void onDateSet(DatePicker view, int year,
android:layout_height="wrap_content" int monthOfYear, int dayOfMonth) {
android:text="SELECT TIME" txtDate.setText(dayOfMonth + "-" +
android:id="@+id/btn_time" (monthOfYear + 1) + "-" + year);
android:layout_below="@+id/btn_date" }
android:layout_alignLeft="@+id/btn_date" }, mYear, mMonth, mDay);
android:layout_alignStart="@+id/btn_date" /> datePickerDialog.show();
</RelativeLayout> }
if (v == btnTimePicker) {
Manifest.xml final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
<?xml version="1.0" encoding="utf-8"?> TimePickerDialog timePickerDialog = new
<manifest TimePickerDialog(this,
xmlns:android="http://schemas.android.com/apk/res/android" new TimePickerDialog.OnTimeSetListener() {
package="com.firstapp.practical16"> @Override
<application public void onTimeSet(TimePicker view, int
android:allowBackup="true" hourOfDay, int minute) {
android:icon="@mipmap/ic_launcher" txtTime.setText(hourOfDay + ":" + minute);
android:label="@string/app_name" }
android:roundIcon="@mipmap/ic_launcher_round" }, mHour, mMinute, false);
android:supportsRtl="true" timePickerDialog.show();
android:theme="@style/Theme.Practical16"> }
<activity android:name=".question_2"></activity> }
<activity }
android:name=".MainActivity"
android:exported="true"> Output
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
</manifest>

question2.java
package com.firstapp.practical16;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
Practical No. 17
Que 1.Write a program to create a HelloWorld Activity using all lifecycles methods to display messages using Log.d.
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_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.firstapp.practical_17;

import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
String msg = "Android : ";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg, "The onCreate() event");
}
@Override
protected void onStart() {
super.onStart();
Log.d(msg, "The onStart() event");
}
protected void onResume() {
super.onResume();
Log.d(msg, "The onResume() event");
}
/** Called when another activity is taking focus. */
@Override
protected void onPause() {
super.onPause();
Log.d(msg, "The onPause() event");
}
@Override
protected void onStop() {
super.onStop();
Log.d(msg, "The onStop() event");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d(msg, "The onDestroy() event");
}
}

output
Practical No.18
Que 1. Write a program to create a text field and a button “Navigate”.
activity_main.xml
Output
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/next"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/next"
android:layout_gravity="right"/>
<EditText
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="search_hint"
android:layout_marginTop="123dp"
android:inputType="text"
android:imeOptions="actionSend" />
<Button
android:id="@+id/buttonUrl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Navigate"
android:textColor="@color/black"
android:layout_gravity="center"
android:background="@color/purple_700"/>
</LinearLayout>

MainActivity.java
package com.firstapp.practical_18;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {


private Button button;
public void onCreate(Bundle savedInstanceState) {
final Context context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView next = findViewById(R.id.next);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(MainActivity.this,question_2.class);
startActivity(intent);
finish();
}
});

button = (Button) findViewById(R.id.buttonUrl);


button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, WebViewActivity.class);
startActivity(intent);
}

});

}
Que 2.Write a program to create button “Start Dialer”. When u click on this button it should open the phone dialer.

android:name=".Answer"></activity>
<activity android:name=".question_3" />
activity_question2.xml <activity android:name=".question_2" />
<activity android:name=".WebViewActivity"
<?xml version="1.0" encoding="utf-8"?> />
<LinearLayout <activity
xmlns:android="http://schemas.android.com/apk/res/android" android:name=".MainActivity"
android:layout_width="fill_parent" android:exported="true">
android:layout_height="fill_parent" <intent-filter>
android:layout_gravity="center_vertical" <action
android:orientation="vertical"> android:name="android.intent.action.MAIN" />
<ImageView <category
android:id="@+id/next" android:name="android.intent.category.LAUNCHER" />
android:layout_width="30dp" </intent-filter>
android:layout_height="30dp" </activity>
android:src="@drawable/next" </application>
android:layout_gravity="right"/>
<Button </manifest>
android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content" Output
android:text="Start Dialer"
android:gravity="center"/>
</LinearLayout>

Question_2.java
package com.firstapp.practical_18;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class question_2 extends Activity {


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_question2);
ImageView next = findViewById(R.id.next);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(question_2.this,question_3.class);
startActivity(intent);
finish();
}
});
Button btn = (Button) findViewById(R.id.btn);
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("android.intent.action.DIAL");
startActivity(intent);
}
};
btn.setOnClickListener(listener);
}
}

manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/
android"
package="com.firstapp.practical_18">
<uses-permission
android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Practical_18"
android:usesCleartextTraffic="true">
<activity
Que 3. Write a program to create two screens. First screen will take one number input from user. After click on
Factorial button, second screen will open and it should display factorial of the same number. Also specify which
type of intent you will use in this case.
question_3.xml Output

<?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=".question_3">
<EditText
android:id="@+id/input_num"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginEnd="120dp"
android:layout_marginTop="180dp"
android:hint="Enter No "/>
<Button
android:id="@+id/ok_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="120dp"
android:text="Factorial"/>
</LinearLayout>

Question_3.java
package com.firstapp.practical_18;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
public class question_3 extends AppCompatActivity implements
View.OnClickListener {
EditText editText;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_question3);
editText = (EditText) findViewById(R.id.input_num);
button = (Button) findViewById(R.id.ok_button);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
switch (v.getId()) {
case R.id.ok_button:
int val = Integer.parseInt(editText.getText().toString());
bundle.putInt("nval", val);
Intent intent = new Intent(this, Answer.class);
intent.putExtras(bundle);
startActivity(intent);
break;
}
}
}

You might also like