Android Practical Lab Manual CSE
Android Practical Lab Manual CSE
LAB MANUAL
DEVELOPMENT OF
ANDROID
APPLICATION
NAME - ROHAN
COURSE - POLYTECHNIC
BRANCH - CSE 2ND YEAR
POLYTECHNIC CSE PRACTICAL
LAB MANUAL
PRACTICAL LIST
COMPUTER SCIENCE AND
ENGINEERING 3RD YEAR
NAME - ROHAN
COURSE - POLYTECHNIC
BRANCH - CSE 3RD YEAR
HOW TO CONDUCT CSE LAB PRACTICAL AND
RULES -
2. Every student should have carry a fair register For Note Down
Summary of Practical which was do him/her in Lab.
Theory -
How to Install and Set up Android Studio on Windows?
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
PRACTICAL NO: 2
OBJECT - Write a program to demonstrate activity (Application
Life Cycle)
THEORY -
INSTRUCTOR - ROHAN
/** Called when the activity is about to become visible. */
@Override
protected void onStart() {
super.onStart();
Log.d(msg, "The onStart() event");
}
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
INSTRUCTOR - ROHAN
PRACTICAL NO: 3
OBJECT - Write a program to demonstrate different types of layouts
THEORY -
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
</LinearLayout>
INSTRUCTOR - ROHAN
<!-- Relative Layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:layout_alignParentStart="true" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 4"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<!-- Constraint Layout -->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
INSTRUCTOR - ROHAN
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Button 3 Clicked", Toast.LENGTH_SHORT).show();
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Button 4 Clicked", Toast.LENGTH_SHORT).show();
}
});
button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Button 5 Clicked", Toast.LENGTH_SHORT).show();
}
});
button6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Button 6 Clicked", Toast.LENGTH_SHORT).show();
}
});
}
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
PRACTICAL NO: 5
OBJECT - Programming exercises on formatting input/output using
printf and scanf and their return type values.
INSTRUCTOR - ROHAN
<!-- Text View to display our basic heading of "calculator"-->
<TextView
android:layout_width="194dp"
android:layout_height="43dp"
android:layout_marginStart="114dp"
android:layout_marginLeft="114dp"
android:layout_marginTop="58dp"
android:layout_marginEnd="103dp"
android:layout_marginRight="103dp"
android:layout_marginBottom="502dp"
android:scrollbarSize="30dp"
android:text=" Calculator"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
INSTRUCTOR - ROHAN
<!-- Edit Text View to input 2nd value-->
<EditText
android:id="@+id/num2"
android:layout_width="363dp"
android:layout_height="30dp"
android:layout_marginStart="72dp"
android:layout_marginTop="112dp"
android:layout_marginEnd="71dp"
android:layout_marginBottom="374dp"
android:background="@android:color/white"
android:ems="10"
android:onClick="clearTextNum2"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
INSTRUCTOR - ROHAN
<!-- A button to perform 'sum' operation -->
<Button
android:id="@+id/sum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="307dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doSum"
android:text="+"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="210dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="113dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doSub"
android:text="-"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.507" />
INSTRUCTOR - ROHAN
<Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="307dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doDiv"
android:text="/"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
INSTRUCTOR - ROHAN
<!-- A button to perform a modulus function. -->
<Button
android:id="@+id/button"
android:layout_width="103dp"
android:layout_height="46dp"
android:layout_marginStart="113dp"
android:layout_marginTop="356dp"
android:layout_marginEnd="206dp"
android:layout_marginBottom="199dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doMod"
android:text="%(mod)"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.515" />
<Button
android:id="@+id/pow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="113dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="210dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doPow"
android:text="n1^n2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.507" />
</androidx.constraintlayout.widget.ConstraintLayout>
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
File: MainActivity.java
package com.example.calculator2;
import android.os.Bundle;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.example.calculator2.databinding.ActivityMainBinding;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
INSTRUCTOR - ROHAN
public boolean getNumbers() {
//checkAndClear();
// defining the edit text 1 to e1
e1 = (EditText) findViewById(R.id.num1);
INSTRUCTOR - ROHAN
if((!s1.equals(null) && s2.equals(null))|| (!s1.equals("") && s2.equals("")) ){
e2.setText(result);
return false;
}
if((s1.equals(null) && !s2.equals(null))|| (s1.equals("") && !s2.equals("")) ){
//checkAndClear();
String result = "Please enter value 1";
e1.setText(result);
return false;
}
if((s1.equals(null) && s2.equals(null))|| (s1.equals("") && s2.equals("")) ){
//checkAndClear();
String result1 = "Please enter value 1";
e1.setText(result1);
String result2 = "Please enter value 2";
e2.setText(result2);
return false;
}
else {
// converting string to int.
num1 = Integer.parseInt(s1);
return true;
}
INSTRUCTOR - ROHAN
public void doSum(View v) {
}
public void clearTextNum1(View v) {
//checkAndClear();
// get the input numbers
if (getNumbers()) {
double sum = Math.pow(num1, num2);
t1.setText(Double.toString(sum));
}
else
{
t1.setText("Error Please enter Required Values");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this,
R.id.nav_host_fragment_content_main);
return NavigationUI.navigateUp(navController, appBarConfiguration)
|| super.onSupportNavigateUp();
}
}
INSTRUCTOR - ROHAN
PRACTICAL NO: 6
THEORY -
INSTRUCTOR - ROHAN
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
ListView l;
String tutorials[]
= { "Algorithms", "Data Structures",
"Languages", "Interview Corner",
"GATE", "ISRO CS",
"UGC NET CS", "CS Subjects",
"Web Technologies" };
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
l = findViewById(R.id.list);
ArrayAdapter<String> arr;
arr
= new ArrayAdapter<String>(
this,
R.layout.support_simple_spinner_dropdown_item,
tutorials);
l.setAdapter(arr);
}
}
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
PRACTICAL NO: 7
OBJECT - Write a program to demonstrate Date picker and time picker
THEORY -
INSTRUCTOR - ROHAN
Step 3 − Add the following code to src/MainActivity.java
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import java.util.Calendar;
public class MainActivity extends AppCompatActivity implements
DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {
TextView textView;
Button button;
int day, month, year, hour, minute;
int myday, myMonth, myYear, myHour, myMinute;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
button = findViewById(R.id.btnPick);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this,
MainActivity.this,year, month,day);
datePickerDialog.show();
}
});
}
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
myYear = year;
myday = day;
myMonth = month;
Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR);
minute = c.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this,
MainActivity.this, hour, minute, DateFormat.is24HourFormat(this));
timePickerDialog.show();
}
INSTRUCTOR - ROHAN
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
myHour = hourOfDay;
myMinute = minute;
textView.setText("Year: " + myYear + "
"+
"Month: " + myMonth + "
"+
"Day: " + myday + "
"+
"Hour: " + myHour + "
"+
"Minute: " + myMinute);
}
}
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
PRACTICAL NO: 8
OBJECT - Programming exercises on switch statement C.
THEORY -
INSTRUCTOR - ROHAN
INSTRUCTOR - ROHAN
RESULT - we successfully understand and execute the switch
statement.
INSTRUCTOR - ROHAN
PRACTICAL NO: 9
OBJECT - Programming exercises on while and do - while statement.
THEORY -
C While Loop
INSTRUCTOR - ROHAN
C Do/While Loop
INSTRUCTOR - ROHAN
PRACTICAL NO: 10
OBJECT - Programming exercises on for statement.
THEORY -
C For Loop
INSTRUCTOR - ROHAN
RESULT - we successfully understand and execute the for
statement.
INSTRUCTOR - ROHAN
PRACTICAL NO: 10
OBJECT - Programming exercises on for statement.
THEORY -
C For Loop
INSTRUCTOR - ROHAN