Android send array from classA to classB
in class A I have a array
final Integer[] images = {R.drawable.aa, R.drawable.aa2, R.drawable.aa3, R.drawable.aa4, R.drawable.aa5};
I need to send this array to class开发者_运维百科 B and make something like this:
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View viev) {
// TODO Auto-generated method stub
image.setImageResource(images[0]);
}
});
Button button2 = (Button)findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View viev) {
// TODO Auto-generated method stub
image.setImageResource(images[1]);
}
});
Since Resources are accessible for all the application you dont need to pass the array. Just intialize it in the Class B, IF you don't affect it in Class A.
If I understand you correctly ,you want to pass integer array from one activity to another. in that can you can try follow code;
Intend i = new Intent(A.this,B.class);
i.putIntegerArrayListExtra(String name, ArrayList<Integer> value);
startActivity(i);
精彩评论