Click button to pass data from edittext to textview in the same page

Tags: ,



I want to create a simple program by put data in edit text to display in text view in the same activity.it is look like below image.

android passing data program

How can I do this? Thanks.

Answer

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView yourTextview = (TextView)findViewById(R.id.yourTextviewId);
    EditText yourEditText = (EditText)findViewById(R.id.yourTextviewId);
    Buton yourOkButton = (Button)findViewById(R.id.yourOkButtonId);

    yourOkButton.setOnClickListener(
        new View.OnClickListener()
        {
            public void onClick(View view)
            {
                yourTextview.setText(yourEditText.getText().toString());
            }
        });
}

Hope it helps



Source: stackoverflow