[英]Show text on other activity than the button clicked
我知道如何在同一页面上单击按钮来显示文本,但是我的问题是(由于我在Google上找不到任何内容):单击按钮时,是否有可能在其他活动中显示文本?
Yes, you can 是的你可以
In your FirstActivity
execute this when button is clicked: 在您的FirstActivity
中,单击按钮时执行以下操作:
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("data","Messsage to be sent");
startActivity(intent);
In your SecondActivity
inside onCreate()
: 在您的SecondActivity
内部的onCreate()
:
String someData = getIntent().getStringExtra("data");
yourTextView.setText(someData);
You can use Intent
for this. 您可以为此使用Intent
。 Intent
is used to move on other activity from first activity. Intent
用于从第一个活动继续进行其他活动。
You can use : 您可以使用 :
Intent i = new Intent(MainActivity.this,SecondActivity.class);
i.putExtra("YourValueKey", yourData.getText().toString());
then you can get it from your second activity by : 那么您可以通过以下方式从第二个活动中获取它:
Intent intent = getIntent();
String YourtransferredData = intent.getExtras().getString("YourValueKey");
If you need pass values between the activities you use this: 如果您需要在活动之间传递值,请使用以下命令:
String name="aaaa";
Intent intent=new Intent(Main_Activity.this,Other_Activity.class);
intent.putExtra("name", name);
startActivity(intent);
And this code to recovery data on new Activity: 并使用以下代码恢复新Activity上的数据:
Bundle b = new Bundle();
b = getIntent().getExtras();
String name = b.getString("name");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.