Skip to content
Advertisement

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

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.

Advertisement

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

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement