如何在不同的活动中将一个TextView的值传递给另一个TextView [英] How to pass value of one TextView to another TextView in different Activity

查看:237
本文介绍了如何在不同的活动中将一个TextView的值传递给另一个TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何将对象从一项活动传递给另一项活动Android

我有两个活动Activity 1Activity 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆