Here I give full source code in Java and XMl, Sample output with mobile application in .apk format.
EX.NO 2.a. Develop an application that uses Table Layout manager and Event Listener
Aim:
To develop an application that uses Table Layout manager and Event Listener
Procedure:
Create an XML file with table layout.
Give separate ID for each and every fields of the XML file.
Create a Java file with event listener for XML file.
Set an actionListener and eventListener commands to specify and perform the operations.
Using the OnClickListener create a method for the button clicking events used in Java
PROGRAM:
XML CODING:
File Name: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:layout_width="match_parent" android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:stretchColumns="*">
<TableRow>
<TextView android:layout_width="match_parent" android:text="Persentage Calculator"
android:layout_span="2"
android:gravity="center" android:textStyle="bold" android:textSize="20sp"/>
</TableRow>
<TableRow>
<TextView android:text="Tamil"/>
<EditText android:width="220dp" android:id="@+id/a1"/>
</TableRow>
<TableRow>
<TextView android:text="English"/>
<EditText android:width="220dp" android:id="@+id/a2"/>
</TableRow>
<TableRow>
<TextView android:text="Maths"/>
<EditText android:width="220dp" android:id="@+id/a3"/>
</TableRow>
<TableRow>
<TextView android:text="Science"/>
<EditText android:width="220dp" android:id="@+id/a4"/>
</TableRow>
<TableRow>
<TextView android:text="Social"/>
<EditText android:width="220dp" android:id="@+id/a5"/>
</TableRow>
<TableRow>
<TextView android:text="Total"/>
<EditText android:width="220dp" android:id="@+id/a6"/>
</TableRow>
<TableRow>
<TextView android:text="Average"/>
<EditText android:width="220dp" android:id="@+id/a7"/>
</TableRow>
<TableRow>
<TextView android:text="Results"/>
<EditText android:width="220dp" android:id="@+id/a8"/>
</TableRow>
<TableRow>
<Button android:text="Submit" android:onClick="calculate"/>
</TableRow>
</TableLayout>
JAVA CODING:
File Name: MainActivity.java
package com.example.expriment2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText a1,a2,a3,a4,a5,a6,a7,a8;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
a1=findViewById(R.id.a1);
a2=findViewById(R.id.a2);
a3=findViewById(R.id.a3);
a4=findViewById(R.id.a4);
a5=findViewById(R.id.a5);
a6=findViewById(R.id.a6);
a7=findViewById(R.id.a7);
a8=findViewById(R.id.a8);
}
public void calculate(View v)
{
int a=Integer.parseInt(a1.getText().toString());
int b=Integer.parseInt(a2.getText().toString());
int c=Integer.parseInt(a3.getText().toString());
int d=Integer.parseInt(a4.getText().toString());
int e=Integer.parseInt(a5.getText().toString());
int tot=a+b+c+d+e;
int avg=tot/5;
a6.setText(String.valueOf(tot));
a7.setText(String.valueOf(avg));
a8.setText(a>40&& b>40&&c>40&&d>40 &&e>40?"Pass":"Fail");
}
}
OUTPUT:



Result:
Thus a Simple Android Application that uses table layout manager and event listener developed and executed successfully.
Here I was attach my Mobile Application in .apk format.
Click on blow link: (Download the mobile app)
https://drive.google.com/file/d/1R5mWxvXD8n8ir5slOal8pzN-lC3U54p5/view?usp=sharing
Any quires leave a comment , I will Try to answer soon.