我想通过两个值到另一个活动,我可以做到这一点与putExtra或做我必须做一个更复杂的方式,这似乎从我的阅读。例如..可以像这样的工作?
I want to pass two values to another activity can I do this with putExtra or do I have to do it a more complicated way, which it seems from my reading. E.g.. can something like this work?
public final static String ID_EXTRA="com.fnesse.beachguide._ID";
Intent i = new Intent(this, CoastList.class);
i.putExtra(ID_EXTRA, "1", "111");
startActivity(i);
上面给出了一个错误。
The above gives an error.
修改
我想的第一件事是相似的:
The first thing I tried was similar to:
i.putExtra(ID_EXTRA1, "1");
i.putExtra(ID_EXTRA2, "111");
但ID_EXTRA2似乎改写ID_EXTRA1
but ID_EXTRA2 seems to write over ID_EXTRA1
因此,
i.putExtra(ID_EXTRA, new String[] { "1", "111"});
貌似走,但我怎么从第二个活动的数组中提取的值,我已经使用这个为一个值是。
Looks like the go but how do I extract the values from the array in the second activity, I have been using this for a single value.
passedVar = getIntent().getStringExtra(CoastList.ID_EXTRA);
我想我必须把ID_EXTRA到一个数组不知何故???
I guess I have to turn ID_EXTRA into an array somehow???
您可以通过使用多个键传递多个值。而不是
You can pass multiple values by using multiple keys. Instead of
i.putExtra(ID_EXTRA, "1", "111");
DO
i.putExtra(ID_EXTRA1, "1");
i.putExtra(ID_EXTRA2, "111");
当然,你必须定义2常量的钥匙,并有在新的活动分开读取这两种。
Of course you have to define 2 constants for the keys and have to read both seperately in the new activity.
或者你也可以通过
i.putExtra(ID_EXTRA, new String[] { "1", "111"});