0% found this document useful (0 votes)
41 views31 pages

CSE3075 - MAD - Second Set Experiments

The document describes designing an application to select course electives using a spinner. It includes XML layout code with views like textviews, edittexts and a spinner to select electives. The Java code will populate the spinner and get the user input on submit.

Uploaded by

rogergold199
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views31 pages

CSE3075 - MAD - Second Set Experiments

The document describes designing an application to select course electives using a spinner. It includes XML layout code with views like textviews, edittexts and a spinner to select electives. The Java code will populate the spinner and get the user input on submit.

Uploaded by

rogergold199
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Experiment – 3

Aim: Design an application to fill the registration form using AutoCompleteTextView and
RadioButton by reading the input from user

Solution:
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:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registration Form"
android:textSize="34sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/nameLbl"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.605"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/nameLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/FNameLbl"
app:layout_constraintEnd_toStartOf="@+id/NameBox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header" />

<AutoCompleteTextView
android:id="@+id/PlaceBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Location"
android:minHeight="48dp"
app:layout_constraintBottom_toTopOf="@+id/SubmitBtn"
app:layout_constraintStart_toEndOf="@+id/PlaceLbl"
app:layout_constraintTop_toBottomOf="@+id/GenderGroup"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/PlaceLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Place of Birth"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/GenderGroup"
app:layout_constraintEnd_toStartOf="@+id/PlaceBox"
app:layout_constraintBottom_toTopOf="@+id/SubmitBtn"/>

<TextView
android:id="@+id/GenderLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/PlaceLbl"
app:layout_constraintEnd_toStartOf="@+id/GenderGroup"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/FNameLbl" />

<TextView
android:id="@+id/FNameLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Father Name"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/GenderLbl"
app:layout_constraintEnd_toStartOf="@+id/FNameBox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nameLbl" />

<RadioGroup
android:id="@+id/GenderGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@+id/GenderLbl"
app:layout_constraintBottom_toTopOf="@+id/PlaceBox"
app:layout_constraintTop_toBottomOf="@+id/FNameBox"
app:layout_constraintEnd_toEndOf="parent">

<RadioButton
android:id="@+id/MaleBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />

<RadioButton
android:id="@+id/FemaleBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />

</RadioGroup>

<EditText
android:id="@+id/NameBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Name"
android:inputType="text"
android:minHeight="48dp"
app:layout_constraintBottom_toTopOf="@+id/FNameBox"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/nameLbl"
app:layout_constraintTop_toBottomOf="@+id/header" />

<EditText
android:id="@+id/FNameBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Father Name"
android:inputType="text"
android:minHeight="48dp"
app:layout_constraintBottom_toTopOf="@+id/GenderGroup"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/FNameLbl"
app:layout_constraintTop_toBottomOf="@+id/NameBox" />

<Button
android:id="@+id/SubmitBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/PlaceBox"
app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java:
package com.example.registrationformacrg;

import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


EditText name,fname;
AutoCompleteTextView places;
RadioGroup rg;
RadioButton rb;
Button btn;
String[] Locations = {"Bangalore","Delhi","Pune","Bombay","Chennai","Hyderabad","Calcutta"};
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.NameBox);
fname = findViewById(R.id.FNameBox);
places = findViewById(R.id.PlaceBox);
btn = findViewById(R.id.SubmitBtn);
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.select_dialog_item,Locations);
places.setThreshold(1);
places.setAdapter(adapter);
rg = findViewById(R.id.GenderGroup);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
rb = findViewById(checkedId);
}
});
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String res1 = "Name: "+name.getText().toString()+"\nFather Name:
"+fname.getText().toString()+"\nGender: "+rb.getText()+"\nPlace of Birth:
"+places.getText().toString();
Toast.makeText(MainActivity.this,res1,Toast.LENGTH_SHORT).show();
}
});
}
Output:
Experiment – 4
Aim: Design an application to fill the course selection of discipline electives for upcoming
semester using Spinner by reading the input from user

Solution:
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:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Electives Selection"
android:textSize="34sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/nameBox"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/nameLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Name"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/nameBox"
app:layout_constraintTop_toBottomOf="@+id/header"
app:layout_constraintBottom_toTopOf="@+id/rollnoLbl"/>

<EditText
android:id="@+id/nameBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:minHeight="48dp"
android:hint="Enter Student Name"
android:inputType="text"
app:layout_constraintStart_toEndOf="@+id/nameLbl"
app:layout_constraintTop_toBottomOf="@+id/header"
app:layout_constraintBottom_toTopOf="@+id/rollnoBox"
app:layout_constraintEnd_toEndOf="parent"/>

<TextView
android:id="@+id/rollnoLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Roll No"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nameLbl"
app:layout_constraintEnd_toStartOf="@+id/rollnoBox"
app:layout_constraintBottom_toTopOf="@+id/delbl"/>

<EditText
android:id="@+id/rollnoBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:minHeight="48dp"
android:hint="Enter Student RollNo"
android:inputType="text"
app:layout_constraintStart_toEndOf="@+id/rollnoLbl"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/delbl"
app:layout_constraintTop_toBottomOf="@+id/nameBox"/>

<TextView
android:id="@+id/delbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Discipline Elective"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/electivesBox"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.054"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rollnoLbl" />

<Spinner
android:id="@+id/electivesBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
app:layout_constraintBottom_toTopOf="@+id/SubmitBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/delbl"/>

<Button
android:id="@+id/SubmitBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:onClick="displayDetails"
app:layout_constraintTop_toBottomOf="@+id/electivesBox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@+id/result"
app:layout_constraintEnd_toStartOf="@+id/ResetBtn"/>

<Button
android:id="@+id/ResetBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:onClick="resetDetails"
app:layout_constraintStart_toEndOf="@+id/SubmitBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/electivesBox"
app:layout_constraintBottom_toTopOf="@+id/result"/>

<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/SubmitBtn"/>
</androidx.constraintlayout.widget.ConstraintLayout>

strings.xml:

<resources>
<string name="app_name">DESelectionSpinner</string>
<string-array name="courses">
<item>Mobile Application Development</item>
<item>Java Full Stack</item>
<item>.Net Full Stack</item>
</string-array>
</resources>

MainActivity.java:

package com.example.deselectionspinner;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


EditText name,rollno;
Spinner elec;
TextView res;
String selectedCourse;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.nameBox);
rollno = findViewById(R.id.rollnoBox);
elec = findViewById(R.id.electivesBox);
res = findViewById(R.id.result);
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item,getResources().getStringArray(R.array.courses));
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
elec.setAdapter(adapter);
elec.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selectedCourse = parent.getItemAtPosition(position).toString();
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
}
public void displayDetails(View v) {
res.setText("Name: "+name.getText().toString()+"\nRoll No:
"+rollno.getText().toString()+"\nSelected Course: "+selectedCourse);
}
public void resetDetails(View v){
name.setText("");
rollno.setText("");
res.setText("");
}
}
Output:
Experiment – 5
Aim: Design an application to check the user is eligibility to vote or not by reading the data of
birth and aadhar card number.

acitivity_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:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vote Eligibility"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/nameBox"/>

<TextView
android:id="@+id/nameLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header"
app:layout_constraintBottom_toTopOf="@+id/aadharLbl"
app:layout_constraintEnd_toStartOf="@+id/nameBox" />

<EditText
android:id="@+id/nameBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:minHeight="48dp"
android:hint="Enter Username"
android:inputType="text"
app:layout_constraintStart_toEndOf="@+id/nameLbl"
app:layout_constraintBottom_toTopOf="@+id/aadharBox"
app:layout_constraintTop_toBottomOf="@+id/header"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/aadharLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aadhar No."
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nameLbl"
app:layout_constraintBottom_toTopOf="@+id/dobLbl"
app:layout_constraintEnd_toStartOf="@+id/aadharBox"/>

<EditText
android:id="@+id/aadharBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:minHeight="48dp"
android:hint="Enter Aadhar Number"
android:inputType="number"
app:layout_constraintStart_toEndOf="@+id/aadharLbl"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nameBox"
app:layout_constraintBottom_toTopOf="@id/dateBox"/>

<TextView
android:id="@+id/dobLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date of Birth"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/checkBtn"
app:layout_constraintTop_toBottomOf="@+id/aadharLbl"
app:layout_constraintEnd_toStartOf="@+id/dateBox"
app:layout_constraintStart_toStartOf="parent"/>

<EditText
android:id="@+id/dateBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:minHeight="48dp"
android:hint="Select Date"
android:inputType="date"
app:layout_constraintStart_toEndOf="@+id/dobLbl"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/aadharBox"
app:layout_constraintBottom_toTopOf="@+id/checkBtn"/>

<Button
android:id="@+id/checkBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check"
android:onClick="checkEligibility"
app:layout_constraintTop_toBottomOf="@+id/aadharBox"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java:

package com.example.agecalcdpd;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity {


EditText name, num, date;
Button btn;
int diff;

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.nameBox);
num = findViewById(R.id.aadharBox);
date = findViewById(R.id.dateBox);
date.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar c = Calendar.getInstance();
int pYear = c.get(Calendar.YEAR);
int pMonth = c.get(Calendar.MONTH);
int pDate = c.get(Calendar.DATE);
DatePickerDialog dialog = new DatePickerDialog(MainActivity.this,
android.R.style.Theme_DeviceDefault_DialogWhenLarge, new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
date.setText(dayOfMonth+"/"+(month+1)+"/"+year);
diff = pYear - year;
}
},pYear, pMonth, pDate);
dialog.show();
}
});
}

public void checkEligibility(View v) {


String s_name = name.getText().toString();
String s_num = num.getText().toString();
Intent in = new Intent(getApplicationContext(), ResultActivity.class);
in.putExtra("NAME",s_name);
in.putExtra("AADHAR",s_num);
in.putExtra("AGE",diff);
startActivity(in);
}
}

activity_result.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=".ResultActivity">

<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
ResultActivity.java:
package com.example.agecalcdpd;
import androidx.appcompat.app.AppCompatActivity;

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

public class ResultActivity extends AppCompatActivity {


TextView res;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
res = findViewById(R.id.result);
Intent intt = getIntent();
String r_name = intt.getStringExtra("NAME");
String r_aadhar = intt.getStringExtra("AADHAR");
int age = intt.getIntExtra("AGE",0);
if(age>=18)
res.setText("Name: "+r_name+"\nAadhar Number: "+r_aadhar+"\n You are eligible to vote");
else
res.setText("Name: "+r_name+"\nAadhar Number: "+r_aadhar+"\n You are not eligible to
vote");
}
}

Output:
Experiment – 6
Aim: Design an application to order the cake by selecting the date and time and display the
order details in another activity.

acitivity_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:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cake Bakery"
android:textSize="34sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/cakeBox"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/itemLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
android:text="Cake Flavour"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/cakeBox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header" />

<Spinner
android:id="@+id/cakeBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="48dp"
app:layout_constraintTop_toBottomOf="@+id/header"
app:layout_constraintBottom_toTopOf="@+id/cakeImage"
app:layout_constraintStart_toEndOf="@+id/itemLbl"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/dateLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date of Delivery"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/cakeImage"
app:layout_constraintTop_toBottomOf="@+id/itemLbl"
app:layout_constraintBottom_toTopOf="@+id/timeLbl" />

<ImageView
android:id="@+id/cakeImage"
android:layout_width="157dp"
android:layout_height="152dp"
app:srcCompat="@drawable/download"
android:onClick="selectDate"
app:layout_constraintBottom_toTopOf="@+id/timeImage"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/dateLbl"
app:layout_constraintTop_toBottomOf="@+id/cakeBox" />

<TextView
android:id="@+id/timeLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time of Delivery"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/orderBtn"
app:layout_constraintEnd_toStartOf="@id/timeImage"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dateLbl"
android:contentDescription="@null"/>

<ImageView
android:id="@+id/timeImage"
android:layout_width="192dp"
android:layout_height="102dp"
android:onClick="selectTime"
app:layout_constraintBottom_toTopOf="@+id/orderBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/timeLbl"
app:layout_constraintTop_toBottomOf="@+id/cakeImage"
app:srcCompat="@drawable/_90436_time" />

<Button
android:id="@+id/orderBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Place Order"
android:onClick="placeOrder"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/timeImage"/>
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java:

package com.example.cakedelapptp;

import androidx.appcompat.app.AppCompatActivity;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.Spinner;
import android.widget.TimePicker;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity {


Spinner cakeitem;
String[] cakes = {"Vanilla","Red Velvet","Choclate","Strawberry","Butterscotch"};
String c_flavour,datedel,timedel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cakeitem = findViewById(R.id.cakeBox);
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item,cakes);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cakeitem.setAdapter(adapter);
cakeitem.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
c_flavour = parent.getItemAtPosition(position).toString();
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
}
public void selectDate(View v){
Calendar c = Calendar.getInstance();
int pYear = c.get(Calendar.YEAR);
int pMonth = c.get(Calendar.MONTH);
int pDate = c.get(Calendar.DATE);
DatePickerDialog dialog = new DatePickerDialog(this,
android.R.style.Theme_DeviceDefault_DialogWhenLarge, new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
datedel = dayOfMonth+"/"+(month+1)+"/"+year;
}
},pYear,pMonth,pDate);
dialog.show();
}
public void selectTime(View v){
Calendar c1 = Calendar.getInstance();
int pHour = c1.get(Calendar.HOUR);
int pMinute = c1.get(Calendar.MINUTE);
TimePickerDialog tdialog = new TimePickerDialog(this,
android.R.style.Theme_DeviceDefault_DialogWhenLarge, new
TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
timedel = hourOfDay+":"+minute;
}
},pHour,pMinute,false);
tdialog.show();
}
public void placeOrder(View v) {
Intent in = new Intent(getApplicationContext(), OrderActivity.class);
in.putExtra("ITEM",c_flavour);
in.putExtra("DATE",datedel);
in.putExtra("TIME",timedel);
startActivity(in);
}
}

Activity_order.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=".OrderActivity">

<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

OrderActivity.java:

package com.example.cakedelapptp;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class OrderActivity extends AppCompatActivity {


TextView res;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order);
res = findViewById(R.id.result);
Intent intt = getIntent();
String cakeFlavour = intt.getStringExtra("ITEM");
String dated = intt.getStringExtra("DATE");
String timed = intt.getStringExtra("TIME");
res.setText("Your Order Placed Successfully."+"\nYour "+cakeFlavour+" cake will be delivered
on"+dated+"\nat"+timed);
}
}
Output:
Experiment – 7
Aim: Design an application to provide the nutrition details of burger and pizza by using
fragments.

acitivity_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">

<ImageView
android:id="@+id/burgerBtn"
android:layout_width="180dp"
android:layout_height="205dp"
app:srcCompat="@drawable/photo_1571091718767_18b5b1457add"
android:onClick="changeFragment"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/pizzaBtn"
app:layout_constraintBottom_toTopOf="@+id/fragmentPortion"/>

<ImageView
android:id="@+id/pizzaBtn"
android:layout_width="179dp"
android:layout_height="184dp"
app:srcCompat="@drawable/pizza_recipe_1"
android:onClick="changeFragment"
app:layout_constraintStart_toEndOf="@+id/burgerBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/fragmentPortion"/>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentPortion"
android:name="com.example.fragmentsexample.BlankFragment"
android:layout_width="375dp"
android:layout_height="375dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/burgerBtn"/>

</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java:

package com.example.fragmentsexample;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

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

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void changeFragment(View v){
Fragment frag;
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
if(v==findViewById(R.id.burgerBtn)){
frag = new BlankFragment();
ft.replace(R.id.fragmentPortion,frag);
ft.commit();
}
if(v==findViewById(R.id.pizzaBtn)){
frag = new BlankFragment2();
ft.replace(R.id.fragmentPortion,frag);
ft.commit();
}
}
}

fragment_blank.xml:

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


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#BF9000"
tools:context=".BlankFragment">

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="24dp"
android:textStyle="bold"
android:textAlignment="center"
android:textColor="#990000"
android:text = "Burger Details\nCalories:354\nFat:18g\nProtein:22g"
android:gravity="center_vertical"
tools:ignore="RtlCompat" />

</FrameLayout>

BlankFragment.java:

package com.example.fragmentsexample;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* A simple {@link Fragment} subclass.
* Use the {@link BlankFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class BlankFragment extends Fragment {

// TODO: Rename parameter arguments, choose names that match


// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

// TODO: Rename and change types of parameters


private String mParam1;
private String mParam2;

public BlankFragment() {
// Required empty public constructor
}

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment BlankFragment.
*/
// TODO: Rename and change types and number of parameters
public static BlankFragment newInstance(String param1, String param2) {
BlankFragment fragment = new BlankFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_blank, container, false);
}
}

fragment_blank2.xml:

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


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#38761d"
tools:context=".BlankFragment2">

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="24dp"
android:textStyle="bold"
android:textAlignment="center"
android:textColor="#85200c"
android:text = "Pizza Details\nCalories:285\nFat:10g\nProtein:12g"
android:gravity="center_vertical"
tools:ignore="RtlCompat" />

</FrameLayout>
BlankFragment2.xml:

package com.example.fragmentsexample;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* A simple {@link Fragment} subclass.
* Use the {@link BlankFragment2#newInstance} factory method to
* create an instance of this fragment.
*/
public class BlankFragment2 extends Fragment {

// TODO: Rename parameter arguments, choose names that match


// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

// TODO: Rename and change types of parameters


private String mParam1;
private String mParam2;

public BlankFragment2() {
// Required empty public constructor
}

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment BlankFragment2.
*/
// TODO: Rename and change types and number of parameters
public static BlankFragment2 newInstance(String param1, String param2) {
BlankFragment2 fragment = new BlankFragment2();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_blank2, container, false);
}
}

Output:
Experiment – 8
Aim: Design an application to provide the student details with section number using
fragments.

acitivity_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">

<ListView
android:id="@+id/studentList"
android:layout_width="175dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/fragmentPortion"
app:layout_constraintBottom_toBottomOf="parent"/>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentPortion"
android:name="com.example.studentdetailsfragments.DetailsFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/studentList"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java:

package com.example.studentdetailsfragments;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Fragment;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity {


ListView list;
String Stu[] = {"ABC","DEF","GHI","JKL"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = findViewById(R.id.studentList);
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,Stu);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DetailsFragment frag = (DetailsFragment)
getSupportFragmentManager().findFragmentById(R.id.fragmentPortion);
frag.change(position);
}
});
}
}

fragment_details.xml:

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


<FrameLayout 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=".DetailsFragment">

<!-- TODO: Update blank fragment layout -->


<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAlignment="center"
android:gravity="center_vertical"
android:text="Name: \nSection Number:"
android:textStyle="bold"
android:textSize="18dp"
tools:ignore="RtlCompat" />

</FrameLayout>

DetailsFragment.java:

package com.example.studentdetailsfragments;

import android.os.Bundle;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
* A simple {@link Fragment} subclass.
* Use the {@link DetailsFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class DetailsFragment extends Fragment {

// TODO: Rename parameter arguments, choose names that match


// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

// TODO: Rename and change types of parameters


private String mParam1;
private String mParam2;
String Users[] = {"ABC","DEF","GHI","JKL"};
String Section[] = {"5CSE1","5CSE2","5CSE3","5CSE4"};
TextView res;

public DetailsFragment() {
// Required empty public constructor
}

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment DetailsFragment.
*/
// TODO: Rename and change types and number of parameters
public static DetailsFragment newInstance(String param1, String param2) {
DetailsFragment fragment = new DetailsFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_details, container, false);
res = view.findViewById(R.id.result);
return view;
}
public void change(int position){
res.setText("Name: "+Users[position]+"\nSection Number: "+Section[position]);
}
}

Output:

You might also like