Reputation: 9
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.
How can I do this? Thanks.
Upvotes: 0
Views: 871
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
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
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