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

Textview and Edit view

The document contains an Android application code that allows users to input text into an EditText field and display it in a TextView when a button is clicked. The layout is defined in XML, featuring a TextView, EditText, and Button arranged vertically. The MainActivity class handles the user interaction by updating the TextView with the input from the EditText upon button press.
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)
6 views3 pages

Textview and Edit view

The document contains an Android application code that allows users to input text into an EditText field and display it in a TextView when a button is clicked. The layout is defined in XML, featuring a TextView, EditText, and Button arranged vertically. The MainActivity class handles the user interaction by updating the TextView with the input from the EditText upon button press.
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

package com.example.

textviewedittextexample;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Initialize Views

TextView textView = findViewById(R.id.textView);

EditText editText = findViewById(R.id.editText);

Button button = findViewById(R.id.button);

// Button Click Event

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// Get text from EditText

String userInput = editText.getText().toString();

// Set text to TextView

textView.setText(userInput);

}
});

<?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 to Display Text -->

<TextView

android:id="@+id/textView"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Enter text below"

android:textSize="18sp"

android:textColor="@android:color/black"

android:padding="8dp"/>

<!-- EditText for User Input -->

<EditText

android:id="@+id/editText"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Type something..."

android:padding="8dp"/>

<!-- Button to Update TextView -->

<Button
android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Update Text"

android:layout_marginTop="16dp"/>

</LinearLayout>

You might also like