将数组传递给其他活动 [英] passing array to other activity
本文介绍了将数组传递给其他活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码将数组传递给其他活动我需要从用户输入数字到int数组然后传递它。怎么办呢?
第一次活动
I have this code to passing array to other activity I need enter the number to int array from user and then pass it. how can do this?
first activity
public void onclick(){
Intent i = new Intent(MainActivity.this, Second.class);
i.putExtra("numbers", array);
startActivity(i);
}
第二项活动
second activity
Bundle extras = getIntent().getExtras();
int[] arrayB = extras.getIntArray("numbers");
textView.setText( ":val:" +arrayB[1]);
finish();
推荐答案
第二项活动:
Second activity:
Intent intent = getIntent();
int[] arrayB = intent.getIntArrayExtra("numbers");
textView.setText( ":val:" +arrayB[1]);
finish();
这篇关于将数组传递给其他活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文