Android tutorial for beginners, Part 3 Edittext,bangla | অ্যান্ড্রয়েড বাংলা টিউটোরিয়াল এডিট টেক্সট

  • 23 April 20
  • Posted By : Admin
  • 104 Hits
  • 10 Comment

How to work with Edittext ,bangla tutorial

}

Java code

Java code below

package com.salam.edittextproject; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Color; 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 { public TextView text1,text2; public Button btn; public EditText edit1,edit2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); edit1 = findViewById(R.id.username); edit2 = findViewById(R.id.userEmail); btn = findViewById(R.id.button); text1 = findViewById(R.id.nameText); text2 = findViewById(R.id.emailText); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String getName = edit1.getText().toString(); String getEmail = edit2.getText().toString(); text1.setText(getName); text1.setTextColor(Color.rgb(255,0,0)); text2.setText(getEmail); } }); } }

Create xml file

Xml code below

<?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" tools:context=".MainActivity" android:orientation="vertical" android:padding="8dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="User name"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/username"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="User email" android:layout_marginTop="30dp"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/userEmail" android:layout_marginBottom="30dp"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button" android:text="Get info"/> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/nameText" android:text="username" android:textColor="#000" android:textSize="24sp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/emailText" android:text="useremail" android:textColor="#000" android:textSize="18sp"/> </LinearLayout> </LinearLayout>