0% found this document useful (0 votes)
19 views3 pages

Java File

The XML file defines the layout of an activity containing text views, edit texts, and a button arranged vertically in a linear layout to collect a username and password. The Java file implements an activity class that retrieves the views by ID, sets an on click listener for the submit button to get the text from the edit texts and display it in a text view. Together, the XML and Java files create a simple login screen application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Java File

The XML file defines the layout of an activity containing text views, edit texts, and a button arranged vertically in a linear layout to collect a username and password. The Java file implements an activity class that retrieves the views by ID, sets an on click listener for the submit button to get the text from the edit texts and display it in a text view. Together, the XML and Java files create a simple login screen application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Xml File: Java File:

<? xml version="1.0" encoding="utf-8"?> package com.example.myapplication;


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" import androidx.appcompat.app.AppCompatActivity;
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" import android.annotation.SuppressLint;
android:layout_width="match_parent" import android.os.Bundle;
android:layout_height="match_parent" import android.view.View;
android:orientation="vertical" import android.widget.Button;
tools:context=".MainActivity"> import android.widget.EditText;
<TextView import android.widget.TextView;
android:layout_width="wrap_content"
android:layout_height="wrap_content" public class MainActivity extends AppCompatActivity {
android:text="Name:"
/> @Override
<EditText protected void onCreate(Bundle savedInstanceState) {
android:layout_width="wrap_content" super.onCreate(savedInstanceState);
android:layout_height="wrap_content" setContentView(R.layout.activity_main);
android:id="@+id/nm" final EditText ed1=(EditText) findViewById(R.id.nm);
/> final EditText ed2=(EditText) findViewById(R.id.ro);
final EditText ed3=(EditText) findViewById(R.id.pe);
<TextView final TextView te1=(TextView) findViewById(R.id.di);
android:layout_width="wrap_content" final Button bt=(Button) findViewById(R.id.btn);
android:layout_height="wrap_content" bt.setOnClickListener(new View.OnClickListener()
android:text="RollNO:" {
/> public void onClick(View view)
<EditText {
android:layout_width="wrap_content" String name=ed1.getText().toString();
android:layout_height="wrap_content" String roll= String.valueOf(ed2.getText());
android:id="@+id/ro"/> String percent= String.valueOf(ed3.getText());
te1.setText("Name:"+name+"\n Roll No:"+roll+"\
<TextView nPercentage:"+percent);
android:layout_width="wrap_content" }
android:layout_height="wrap_content" });
android:text="Percentage:" }
/> }
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/pe"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/btn"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/di"/>
</LinearLayout>

7_2
7_2
7_1

Xml File: Output:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username:"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"/>
</LinearLayout>

You might also like