0

我正在创建一个 android 应用程序,它使用来自单击按钮的数据来生成存储在共享首选项中的答案。当用户单击按钮时,我无法找到必要的意图代码来保存信息,以便可以使用它来计算答案。正如您从代码中看到的那样,当用户单击按钮时,它将生成下一个活动。谢谢!

    Button button18 = (Button) findViewById(R.id.button18);
    button18.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //I need to store the results then move to the next activity shown below?
            Intent i = new Intent(EnterAgeActivity.this, EnterWeightActivity.class);
            startActivity(i);


            // TODO Auto-generated method stub

        }
    });
    `
4

1 回答 1

0

发送带有意图的数据。

@Override
public void onClick(View v) {
    //I need to store the results then move to the next activity shown below?
    Bundle data = new Bundle();
    data.putString(key, value);
    data.putInt(key, value);
    Intent i = new Intent(EnterAgeActivity.this, EnterWeightActivity.class);
    i.putExtra("data", data);
    startActivity(i);
}

EnterWeightActivity oncreate:

@Override
public void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    if(intent.hasExtras) {
        Bundle data = intent.getExtras();
        // Your data
    }
}
于 2013-10-08T10:48:05.400 回答