2

我在我的主 TabActivity 中创建了 4 个活动意图(我添加到 TabHost)。我也有带有 onClick 方法的按钮。单击此按钮时,我会在 Rezultati 活动的意图中添加一些额外内容。现在我正在尝试从此 TabActivity 调用启动活动的自定义方法以使用该附加功能。

以下是创建意图之一的示例:

public class Prvi extends TabActivity {


public Intent rezultati;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    Resources res = getResources(); 
    TabHost tabHost = getTabHost();
    TabHost.TabSpec spec; 
    rezultati = new Intent().setClass(this, Rezultati.class);
        spec = tabHost.newTabSpec("rez").setIndicator("Rezultati",
                          res.getDrawable(R.layout.novice))
                      .setContent(rezultati);
        tabHost.addTab(spec); }

在按钮单击时调用此方法:

public void isci(View view)
{
    EditText iskano = (EditText) findViewById(R.id.iskano);


    rezultati.putExtra("Iskano", iskano.getText().toString()); }

现在我有类 Rezultati.class 我想在其中调用方法更新:

public class Rezultati extends Activity{    
{
    public void update(){
    String value = getIntent().getExtras().getString("Iskano");
    TextView textview = new TextView(this);
    textview.setText(value);
    setContentView(textview);}
}

我尝试在函数 isci(View view) 中创建类 Rezultati 的新实例并调用函数更新

Rezultati r=new Rezultati();
r.update();

除非当我调用 r.update() 时更新函数中没有任何内容,否则它会工作,否则每次都会停止工作。

我究竟做错了什么?

4

1 回答 1

0

请使用GlobalVariablesApplication将 Extras 放入其中,无论您在哪里获得

附加功能

看到这个链接 GlobalVariables

于 2013-07-26T10:34:53.243 回答