Here I give full source code in Java and XMl, Sample output with mobile application in .apk format.
EX.NO 2.b Develop an application that uses Relative Layout manager and Event Listener
Aim:
To develop an application that uses Relative Layout manager and Event Listener
Procedure:
Create an XML file with relative 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"?> <RelativeLayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:id="@+id/tv1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAlignment="center" android:text="Persentage Calculator" /> <TextView android:id="@+id/tv2" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv1" android:text="Tamil" /> <EditText android:id="@+id/et1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv1" android:layout_toRightOf="@+id/tv2" /> <TextView android:id="@+id/tv3" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et1" /> <TextView android:id="@+id/tv4" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv3" android:text="English" /> <EditText android:id="@+id/et2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv3" android:layout_toRightOf="@+id/tv4" /> <TextView android:id="@+id/tv5" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et2" /> <TextView android:id="@+id/tv6" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv5" android:text="Maths" /> <EditText android:id="@+id/et3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv5" android:layout_toRightOf="@+id/tv6" /> <TextView android:id="@+id/tv7" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et3" /> <TextView android:id="@+id/tv8" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv7" android:text="Science" /> <EditText android:id="@+id/et4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv7" android:layout_toRightOf="@+id/tv8" /> <TextView android:id="@+id/tv9" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et4" /> <TextView android:id="@+id/tv10" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv9" android:text="Social" /> <EditText android:id="@+id/et5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv9" android:layout_toRightOf="@+id/tv10" /> <TextView android:id="@+id/tv11" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et5" /> <TextView android:id="@+id/tv12" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv11" android:text="Total" /> <EditText android:id="@+id/et6" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv11" android:layout_toRightOf="@+id/tv12" /> <TextView android:id="@+id/tv13" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et6" /> <TextView android:id="@+id/tv14" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv13" android:text="Result" /> <EditText android:id="@+id/et7" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv13" android:layout_toRightOf="@+id/tv14" /> <TextView android:id="@+id/tv15" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et7" /> <TextView android:id="@+id/tv16" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv15" android:text="Average" /> <EditText android:id="@+id/et8" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv15" android:layout_toRightOf="@+id/tv16" /> <TextView android:id="@+id/tv17" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/et8" /> <Button android:id="@+id/tv18" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@+id/tv17" android:text="Submit" android:onClick="calculate"/> </RelativeLayout>
JAVA CODING:
File Name: MainActivity.java
package com.example.expriment2b;
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.et1);
a2=findViewById(R.id.et2);
a3=findViewById(R.id.et3);
a4=findViewById(R.id.et4);
a5=findViewById(R.id.et5);
a6=findViewById(R.id.et6);
a7=findViewById(R.id.et7);
a8=findViewById(R.id.et8);
}
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 relative 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 run in your mobile)
https://drive.google.com/file/d/1R5mWxvXD8n8ir5slOal8pzN-lC3U54p5/view?usp=sharing
Any quires leave a comment , I will Try to answer soon.