我正在尝试将整数数组传递给baseadapter,以便A.class将整数数组传递给B.class中的BaseAdapter。这里是我想过去的整数数组的A.class(发件人):将整数传递给BaseAdapter
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;
}
}
现在显然上面的代码不正确,我不能用图像适配器中的getintent。但是这是我想要实现的一个说明性示例,并且想知道如果可能,如何通过意图将变量或数组传递给BaseAdapter。
真棒谢谢你!你刚刚救了一天 – benbeel