Search code examples
androidandroid-edittexttextviewgettext

Display users input from editText field on a textView


I use getText(); on an editText using the code below and want the users input to replace a textView then how do I do this?
btw the code was taken from this question:
Get Value of a Edit Text field

Button   mButton;
EditText mEdit;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mButton = (Button)findViewById(R.id.button);
mEdit   = (EditText)findViewById(R.id.edittext);

mButton.setOnClickListener(
    new View.OnClickListener()
    {
        public void onClick(View view)
        {
            Log.v("EditText", mEdit.getText().toString());
        }
    });
}

Solution

  • 1- Find your textView

    TextView txt = (TextView) findViewById(R.id.yourTextView);
    

    2- After you get the text from EditText set it to TextView :

    txt.setText(mEdit.getText().toString());