How to set the value in EditText field?

I have three EditText, I want to concatinate the strings present in the first two EditText fields,and display in the third EditText field.After entering the string at 2nd field,it
automatically concatinate and set in the third EditText.

EditText text1 = (EditText) findViewById(R.id.text1);
mtext1=text1.getText.toString();

EditText text2 = (EditText) findViewById(R.id.text2);
mtext2 = text2.getText.toString();


mtext3=mtext1.concat().mtext2;
Edit text3 = (EditText) findViewById(R.id.text3);
text3 = setText(mtext3.toString());

I wrote the above code.But I result is not shomn in the third EditText.
Please give the solution, that I implement in my program

  • What is the alternative of SlidingDrawer which is deprecated? For sliding up from bottom
  • Gallery space at beginning and end
  • javax.net.ssl.sslpeerunverifiedexception no peer certificate
  • onActivityResult gets called when Activity starts, not when its finished
  • Share memory between two processes in Dalvik
  • Google Mobile Vision Text API Example
  • Related posts:

    Programmatically collapse or expand CollapsingToolbarLayout
    Adding a day to a Calendar in Android fails on 31st
    Mediaplayer error (-38,0) , stop called in state 4
    Android RecyclerView + CursorLoader + ContentProvider + “Load More”
    Native USB Debugging on Chrome 32 doesn't detect device
    Clarification regarding Android “Attribute elevation is only used in API level 21 and high...
  • How to detect orientation change in layout in Android?
  • cordova/phonegap does not make android directory
  • ViewFlipper vs Fragments
  • How can I display a list view in an Android Alert Dialog?
  • Require a password to uninstall/remove application
  • Use google map on any devices. (without google play )
  • 4 Solutions collect form web for “How to set the value in EditText field?”

    This should work. Make sure you do not edit text2 in the TextChanged listener because then afterTextChanged would get called again.

    final EditText text1 = (EditText) findViewById(R.id.text1);
    final EditText text2 = (EditText) findViewById(R.id.text2);
    final EditText text3 = (EditText) findViewById(R.id.text3);
    
    text2.addTextChangedListener(new TextWatcher() {
        void afterTextChanged(Editable s) {
            text3.setText(text1.getText().toString() + text2.getText().toString());
        };
    });
    

    If you want to detect when your two EditText fields change, you’re going to need to use addTextChangedListener() on each of them. The following can go in your onCreate() method:

    final EditText text1 = (EditText) findViewById(R.id.text1);
    final EditText text2 = (EditText) findViewById(R.id.text2);
    final EditText text3 = (EditText) findViewById(R.id.text3);
    
    TextWatcher watcher = new TextWatcher() {
        void afterTextChanged(Editable s) {
            text3.setText(text1.getText() + text2.getText());
        };
    });
    
    text1.addTextChangedListener(watcher);
    text2.addTextChangedListener(watcher);
    
    package com.tiru;
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.EditText;
    
    public class SetEditText extends Activity {
    
        private String mtext1 = null;
        private String mtext2 = null;
        private String mtext3 = null;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            EditText text1 = (EditText) findViewById(R.id.text1);
            EditText text2 = (EditText) findViewById(R.id.text2);
            mtext1 = text1.getText();
            mtext2 = text2.getText();
            mtext3 = mtext1 + mtext2;
            EditText text3 = (EditText) findViewById(R.id.text3);
            text3.setText(mtext3);
        }
    }
    
    EditText inputWeight,inputHeight,outputResult;
    Button calculate;
    float num1,num2,out;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bmi);
    
        inputWeight = (EditText) findViewById(R.id.weight);
        inputHeight = (EditText) findViewById(R.id.height);
        outputResult = (EditText) findViewById(R.id.result);
        calculate = (Button) findViewById(R.id.cal);
    
    
        calculate.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                num1 = Float.parseFloat(inputWeight.getText().toString());
                num2 = Float.parseFloat(inputHeight.getText().toString());
                out=num1/(num2*num2);
                calculate.setText(" "+out);
            }
        });}
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.