显示除点击按钮之外的其他活动的文本

时间:2022-01-26 20:29:10

I know how to show text with a button click on the same page, but my question is (since I couldn't find anything on Google): Is it possible when you click a button, that the text shows up on another activity?

我知道如何通过点击同一页面上的按钮来显示文字,但我的问题是(因为我在Google上找不到任何内容):当您点击按钮时,是否有可能文本显示在另一个活动上?

3 个解决方案

#1


3  

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():

在onCreate()里面的SecondActivity中:

String someData = getIntent().getStringExtra("data");
yourTextView.setText(someData);

#2


0  

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");

#3


0  

You can use Intent for this. Intent is used to move on other activity from first activity.

你可以使用Intent。 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");

#1


3  

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():

在onCreate()里面的SecondActivity中:

String someData = getIntent().getStringExtra("data");
yourTextView.setText(someData);

#2


0  

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");

#3


0  

You can use Intent for this. Intent is used to move on other activity from first activity.

你可以使用Intent。 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");