如何在不同的活动中将一个TextView的值传递给另一个TextView [英] How to pass value of one TextView to another TextView in different Activity
问题描述
我有两个活动Activity 1
和Activity 2
.对于这两个活动,我有两个XML布局1.xml和2.xml.在1.xml中,我有Button
;在2.xml中,我有TextView
.因此,我想单击第一个活动上的Button
,我想打开第二个活动,并且还想在Activity2中出现的Textview
上显示Button
中显示的文本.我的意思是说,假设Button
中的文本为"ADD",那么此文本将显示在TextView
中.
I have two activities Activity 1
and Activity 2
. For these two activities, I have two XML layout 1.xml and 2.xml. In 1.xml I have a Button
and in 2.xml I have TextView
. So what I want is on click of Button
which is on the first activity I want to open the 2nd activity and also want to display the text shown in Button
on the Textview
present in Activity2. I mean to say that suppose the text in the Button
is "ADD" then this text will be displayed in TextView
.
注意:Button
在Activity1上,而TextView
在Activity2上
Note: Button
is on Activity1 and TextView
is on Activity2
推荐答案
INTENT 使用Intent
传递数据,putExtra()
将允许您放置数据
INTENT Use Intent
to pass data, putExtra()
will allow you to put data
活动A
Intent myIntent = new Intent(ActivityA.this, Activityb.class);
myIntent.putExtra("key", "value");
startActivity(myIntent);
活动B
Intent myIntent = getIntent(); // this is just for example purpose
myIntent.getExtra("key");
这篇关于如何在不同的活动中将一个TextView的值传递给另一个TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!