0

我对 Android 编程的理解有问题。

当我想在我的应用程序上添加选项卡时,我使用我的选项卡和与这些选项卡相关的 Intent 创建了一个代码。

现在,我将获得由我的选项卡创建的活动实例。(要检索公共选项卡的字段,例如 2 并与 3 的公共字段连接。所有在我的活动中启动了视线 TabHost)

如何在不使用静态的情况下做到这一点?

提前谢谢你,朱利安。

4

2 回答 2

1

您是否为每个选项卡使用不同的活动?

如果是,并将字段视为字符串,在示例 2 中:

        Intent intent = new Intent(this, YourThirdActivity.class);
        intent.putExtra("Field2", field2.toString());

在示例 3 中:

    intent = getIntent();
    Field2 = intent.getStringExtra("Field2");
于 2012-05-14T14:46:35.880 回答
0

这不是我认为的最佳解决方案,但它有效:

public class Tab2 extends Activity {

static Tab2 Instance;

protected void onCreate(Bundle savedInstanceState) {
Instance = this;
{...}

public class TabMain extends TabActivity {


protected void onCreate(Bundle savedInstanceState) {
{... Create and launch all Intent Tab ...}
String value = Tab2.Instance.MyMethodReturnSomeThing();
{...}

目前,这是我的解决方案。如果你有更好的考虑:/

于 2012-05-15T09:17:43.947 回答