简体   繁体   中英

How to get information from an edit text that is entered by the user and move it to another activity as a TextView

I need to get information thats entered by the user in a EditText and move it to another activity by placing it under everything with a TextView. I'm new to this, and I'm sure it's simple. Please help. Thanks.

You don't want to do what you say you want to do, not exactly. You want to pass the information from one Activity to another, not the actual view.

At the point where you're launching the new activity:

String info = editText.getText().toString();
Intent intent = new Intent(this, MyNewActivity.class);
intent.putExtra("info_key", info);
startActivity(intent);

Then, in your onCreate() in the new Activity:

Intent intent = getIntent();
String info = intent.getStringExtra("info_key");
textView.setText(info);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM