Input and Output String by using EditText and Button
Activiti_main.xml Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.example.seam.addtonumber.MainActivity"> <Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_marginTop="161dp"
app:layout_constraintTop_toBottomOf="@+id/editText"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp" />
<EditText android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="82dp"
app:layout_constraintHorizontal_bias="0.502" />
</android.support.constraint.ConstraintLayout>
Main Activity.java Code:
package com.example.seam.addtonumber; import android.provider.Settings; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private EditText edittext1,edittext2; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setOnbutton(); } public void setOnbutton() { Button bt=(Button) findViewById(R.id.button); //EditText e=(EditText)findViewById(R.id.editText); edittext1=(EditText)findViewById(R.id.editText); bt.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String value1=edittext1.getText().toString(); Toast.makeText(MainActivity.this, value1, Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "Islam", Toast.LENGTH_SHORT).show(); } }); } }
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন