如何改变的TextView的值取决于不同Activites呼叫第一活动的活动的? [英] How to change value of TextView of an activity depending on the different Activites calling the first activity?

查看:174
本文介绍了如何改变的TextView的值取决于不同Activites呼叫第一活动的活动的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个将要减少在Android Project.Suppose我的code尺寸我有一个活动C.活动c具有一个TextView,其值是你好的逻辑。有两个其他活动急症室; B.现在,如果按钮点击活动A调用活动C,TextView的值必须改变,以你怎么样?如果活动B调用活动C,TextView的价值将是我很好。

I need to create a logic which is going to decrease my code size in an Android Project.Suppose I have an Activity C. Activity C have a TextView whose value is "Hello". There are two another Activities A & B. Now, if Activity A on button Click calls Activity C, the value of TextView must change to "How are You?" and if Activity B calls Activity C , TextView value will be "I am Fine".

所以,我的问题是,如何检测其活性调用活动C和改变的TextView的文本因此在运行时?

So, my question is , How to detect which Activity is calling Activity C and change the text of TextView accordingly at runtime ?

任何形式的帮助将是AP preciated。

Any kind of help will be appreciated.

推荐答案

在除了对方回复。您可以发送的消息只是文本,并在活动ç摆脱有条件的检查。

In addition to other replies. You can send just text of the message and get rid of conditional checks in Activity C.

活动的C呼叫:

Intent i = new Intent(this, ActivityC.class);
i.putExtra(ActivityC.MESSAGE_KEY, "How are you?");
startActivity(i);

Intent i = new Intent(this, ActivityC.class);
i.putExtra(ActivityC.MESSAGE_KEY, "I am fine");
startActivity(i);

和在ActivityC:

And in ActivityC:

public final static String MESSAGE_KEY = "com.package.name.ActivityC.message";

@Override
protected void onCreate() {
    ...
    String message = getIntent().getStringExtra(MESSAGE_KEY);
    if (message != null) {
        textView.setText(message);
    }
    ...
}

这篇关于如何改变的TextView的值取决于不同Activites呼叫第一活动的活动的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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