0% found this document useful (0 votes)
48 views

Androidx - Constraintlayout.Widget - Constraintlayout: Edit Text Text View XML

The document contains an XML layout file and Java code for an Android app. The XML defines a constraint layout with a TextView, EditText, and Button. The Java code gets references to these views, sets an onClick listener for the button to get the text from the EditText and set it in the TextView.

Uploaded by

Ss1122
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Androidx - Constraintlayout.Widget - Constraintlayout: Edit Text Text View XML

The document contains an XML layout file and Java code for an Android app. The XML defines a constraint layout with a TextView, EditText, and Button. The Java code gets references to these views, sets an onClick listener for the button to get the text from the EditText and set it in the TextView.

Uploaded by

Ss1122
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Edit text text view XML

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".MainActivity">

<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Roll No "
android:text="Hello World!"
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.265" />

<EditText
android:id="@+id/et2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="none"
android:ems="10"
android:hint="Enter Your Name"
android:inputType="textPersonName"
android:textSize="34sp"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="16dp" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Click Here"
android:text="Button"
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv2"
app:layout_constraintVertical_bias="0.241"
tools:layout_editor_absoluteX="16dp" />

</androidx.constraintlayout.widget.ConstraintLayout>
Java progarm
package com.example.edittext;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {


EditText editTextName;
Button btnClickHere;
TextView textName;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextName=(EditText) findViewById(R.id.et2);
btnClickHere=(Button) findViewById(R.id.button);
textName=(TextView) findViewById(R.id.tv2);
btnClickHere.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name=editTextName.getText().toString();
textName.setText(name);
}
});
}
}

You might also like