Mobile Programming Lab Report - Copy
Mobile Programming Lab Report - Copy
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book Entry"
android:layout_gravity="center"
android:textSize="30sp"
android:layout_marginTop="100sp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Book Title"
android:textSize="25sp"
android:layout_marginTop="20sp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the book title"
android:textSize="15sp"
android:id="@+id/title"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Author Name"
android:textSize="25sp"
android:layout_marginTop="20sp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the author name"
android:textSize="15sp"
android:id="@+id/author"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Book Description"
android:textSize="25sp"
android:layout_marginTop="20sp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the book description"
android:textSize="15sp"
android:id="@+id/description"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Book Price"
android:textSize="25sp"
android:layout_marginTop="20sp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the book price"
android:textSize="15sp"
android:id="@+id/price"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="20sp"
android:layout_marginTop="20sp"
android:layout_marginLeft="40sp"
android:id="@+id/submit"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40sp"
android:layout_marginTop="20sp"
android:text="Cancel"
android:textSize="20sp"
android:id="@+id/cancel"
/>
</LinearLayout>
</LinearLayout>
MainActivity.java
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SI Calculator"
android:textSize="40sp"
android:textAlignment="center"
android:layout_margin="10sp" />
<EditText
android:id="@+id/pri"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Principle"
android:textSize="25sp"
android:layout_margin="10sp" />
<EditText
android:id="@+id/rate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Rate"
android:textSize="25sp"
android:layout_margin="10sp" />
<EditText
android:id="@+id/time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Time"
android:textSize="25sp"
android:layout_margin="10sp" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Calculate"
android:textSize="25sp"
android:layout_gravity="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textAlignment="center"
android:layout_margin="10sp"
android:id="@+id/txt1" />
</LinearLayout>
MainActivity.java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
btn = findViewById(R.id.btn);
pri = findViewById(R.id.pri);
rate = findViewById(R.id.rate);
time = findViewById(R.id.time);
txt1 = findViewById(R.id.txt1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int p =Integer.parseInt(pri.getText().toString());
int r=Integer.parseInt(rate.getText().toString());
int t=Integer.parseInt(time.getText().toString());
int si=(p*t*r)/100;
int e=si+p;
c. Design Employee Entry Form insert the data and show to another activity
entry.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"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Employee Entry Form"
android:textSize="24sp"
android:layout_gravity="center"
android:paddingBottom="10dp"
android:layout_marginTop="30sp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Employee Name"
android:id="@+id/empName"
android:layout_marginTop="10sp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Employee Age"
android:inputType="number"
android:id="@+id/empAge"
android:layout_marginTop="10sp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Department"
android:id="@+id/empDept"
android:layout_marginTop="10sp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Salary"
android:inputType="numberDecimal"
android:id="@+id/empSalary"
android:layout_marginTop="10sp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginTop="20dp"
android:id="@+id/submitBtn"/>
</LinearLayout>
display.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"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Employee Details"
android:textSize="24sp"
android:layout_gravity="center"
android:paddingBottom="10dp"
android:layout_marginTop="30sp"/>
<TextView
android:id="@+id/resultText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"/>
</LinearLayout>
MainActivity.java
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.entry);
empName = findViewById(R.id.empName);
empAge = findViewById(R.id.empAge);
empDept = findViewById(R.id.empDept);
empSalary = findViewById(R.id.empSalary);
submitBtn = findViewById(R.id.submitBtn);
submitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = empName.getText().toString();
int age = Integer.parseInt(empAge.getText().toString());
String department = empDept.getText().toString();
double salary = Double.parseDouble(empSalary.getText().toString());
startActivity(intent);
}
});
}
}
DisplayActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
resultText = findViewById(R.id.resultText);
Intent data = getIntent();
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment Example"
android:textSize="24sp"
android:layout_gravity="center"
android:paddingBottom="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/btnFragment1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment 1"/>
<Button
android:id="@+id/btnFragment2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment 2"
android:layout_marginLeft="10dp"/>
<Button
android:id="@+id/btnFragment3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment 3"
android:layout_marginLeft="10dp"/>
</LinearLayout>
<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"/>
</LinearLayout>
fragment_one.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:gravity="center"
android:background="@android:color/holo_blue_light"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Fragment One"
android:textSize="24sp"/>
</LinearLayout>
fragment_two.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:gravity="center"
android:background="@android:color/holo_green_light"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Fragment Two"
android:textSize="24sp"/>
</LinearLayout>
fragment_three.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:gravity="center"
android:background="@android:color/holo_red_light"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Fragment Three"
android:textSize="24sp"/>
</LinearLayout>
FragmentOne.java
package com.example.fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_one, container, false);
}
}
FragmentTwo.java
package com.example.fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
FragmentThree.java
package com.example.fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_three, container, false);
}
}
MainActivity.java
package com.example.fragment;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
btnFragment1 = findViewById(R.id.btnFragment1);
btnFragment2 = findViewById(R.id.btnFragment2);
btnFragment3 = findViewById(R.id.btnFragment3);
btnFragment1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadFragment(new FragmentOne());
}
});
btnFragment2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadFragment(new FragmentTwo());
}
});
btnFragment3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadFragment(new FragmentThree());
}
});
}
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
fragment_1.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/editTextProductId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Product ID"
android:inputType="number" />
<EditText
android:id="@+id/editTextProductName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Product Name" />
<EditText
android:id="@+id/editTextProductPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Product Price"
android:inputType="numberDecimal" />
<Button
android:id="@+id/buttonSendData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Product Data" />
</LinearLayout>
Fragment1.java
package com.example.tranferdatalab1_5;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
public Fragment1() {}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_1, container, false);
editTextProductId = view.findViewById(R.id.editTextProductId);
editTextProductName = view.findViewById(R.id.editTextProductName);
editTextProductPrice = view.findViewById(R.id.editTextProductPrice);
buttonSendData = view.findViewById(R.id.buttonSendData);
buttonSendData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String productId = editTextProductId.getText().toString();
String productName = editTextProductName.getText().toString();
String productPrice = editTextProductPrice.getText().toString();
return view;
}
}
fragment_2.xml
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
public Fragment2() {}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_2, container, false);
textViewProductDetails = view.findViewById(R.id.textViewProductDetails);
return view;
}
}
MainActivity.java
package com.example.tranferdatalab1_5;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
if (savedInstanceState == null) {
Fragment1 fragment1 = new Fragment1();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, fragment1);
transaction.commit();
}
}
}