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

MAD 7 Practical

The document contains XML and Java code for an Android application layout and its main activity. It includes an EditText for user input, a Button to print the input, and a TextView to display the text. The Java code sets up the UI components and defines a click listener for the button to update the TextView with the input from the EditText.

Uploaded by

aditya23acsn
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)
4 views3 pages

MAD 7 Practical

The document contains XML and Java code for an Android application layout and its main activity. It includes an EditText for user input, a Button to print the input, and a TextView to display the text. The Java code sets up the UI components and defines a click listener for the button to update the TextView with the input from the EditText.

Uploaded by

aditya23acsn
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/ 3

Practical No.

7
xml Code:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/ed1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_x="119dp"
android:layout_y="276dp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="177dp"
android:layout_y="362dp"
android:backgroundTint="@color/design_default_color_secondary"
android:text="Print" />
<TextView
android:id="@+id/t1"
android:layout_width="200dp"
android:layout_height="20dp"
android:layout_x="125dp"
android:layout_y="467dp"
android:gravity="center"
android:text="Text will be displayed here" />
</AbsoluteLayout>
Java Code:
package com.example.pract7;

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

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


EditText ed;
Button bu;
TextView tv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);

// Initialize UI components after setContentView


ed = findViewById(R.id.ed1);
bu = findViewById(R.id.b1);
tv = findViewById(R.id.t1);

bu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String msg = ed.getText().toString();
tv.setText(msg);
}
});
}
}
O/P:

You might also like