如何在android中使用bundle传递Integer []?

时间:2012-03-30 06:09:35

标签: android

      Integer[] image = { 
       R.drawable.image1,
       R.drawable.image22,

   };

如何使用bundle传递此数组?

2 个答案:

答案 0 :(得分:2)

通过使用ArrayList我们可以发送

private ArrayList<Integer> image;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    image = new ArrayList<Integer>();

    image.add(R.drawable.ic_launcher);
    image.add(R.drawable.ic_launcher);

    Button photoButton = (Button) this.findViewById(R.id.button1);
    photoButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {              

            Intent intent = new Intent(PhotoActivity.this,PhotoActivity1.class ); 
            intent.putIntegerArrayListExtra("VALUES", image);               
            startActivity(cameraIntent); 
        }     
    }); 

在接收器类

Intent i = getIntent();
ArrayList<Integer> img = i.getIntegerArrayListExtra("VALUES");

答案 1 :(得分:1)

首先发送

Bundle bnd=new Bundle();
bnd.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(context, Class);
i.putExtras(bnd);

然后在接收方

Bundle b=this.getIntent().getExtras();
String[] array=b.getStringArray(key);