我正在尝试将整数数组传递给 baseadapter,这样 A.class 会将整数数组传递给 B.class 中的 BaseAdapter。这是我在 A.Class (发件人)中传递整数数组的方式:
int [] mThumb = {
R.drawable.image1_thumb, R.drawable.image2_thumb, R.drawable.image3_thumb,
R.drawable.image4_thumb, R.drawable.image5_thumb, R.drawable.image6_thumb,
R.drawable.image7_thumb, R.drawable.image8_thumb, R.drawable.image9_thumb,
R.drawable.image10_thumb};
Bundle b=new Bundle();
b.putIntArray("mThumbSent", mThumb);
Intent startSwitcher = new Intent(A.this, B.class);
startSwitcher.putExtras(b);
在我的活动 B 中的 BaseAdapter 中:
public class ImageSwitch1 extends Activity Extends ...{
onCreate....
[redacted]
}
private ImageSwitcher mSwitcher;
public class ImageAdapter extends BaseAdapter {
Bundle b=this.getIntent().getExtras();
int[] mThumb = b.getIntArray("mThumbSent");
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumb.length; //this used to say return mThumbIds
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView im = new ImageView(mContext);
im.setImageResource(mThumb[position]);
im.setAdjustViewBounds(true);
im.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
im.setBackgroundResource(R.drawable.picture_frame);
return im;
}
private Context mContext;
}
}
现在显然上面的代码不正确,我不能在 imageadapter 中使用 getintent。但这是我试图完成的一个说明性示例,并且想知道如何通过意图将变量或数组传递给 BaseAdapter,如果可能的话。