pherum chheang
pherum chheang

Reputation: 9

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.

Upvotes: 0

Views: 871

Answers (3)

Kush Bhatia
Kush Bhatia

Reputation: 1

In Kotlin you can done like this :

yourButtonID.setOnClickListener
{
     
val textView = findViewById<View>(R.id.yourTextViewID) as TextView
     
textView.setText(yourEditTextID.text.toString())
     
yourTextViewID.text!!.clear()

}

Upvotes: 0

fdelafuente
fdelafuente

Reputation: 1122

@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

Upvotes: 1

VinayagaSundar
VinayagaSundar

Reputation: 1701

Try this one

EditText editText = (EditText) findViewById(R.id.edittext);
TextView textView = (TextView) findViewById(R.id.textview);

Button button = (Button) findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener(View view){
    String text = editText.getText().toString();
    textView.setText(text);
});

Upvotes: 2

Related Questions