Надеюсь, приведенный ниже код пригодится вам.
1-я Активность
ListView listView;
int total_data = 11;
// references to our images
private Integer[] mThumbIds = { R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6,
R.drawable.sample_7, R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3, R.drawable.sample_4,
R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2,
R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7 };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(new ImageAdapter());
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
mThumbIds[arg2]);
Intent intent = new Intent(StackTestActivity.this,
StackTestActivity1.class);
intent.putExtra("bitmap", bitmap);
startActivity(intent);
}
});
}
private class ImageAdapter extends BaseAdapter {
public ImageAdapter() {
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if (convertView == null) {
LayoutInflater li = getLayoutInflater();
v = li.inflate(R.layout.customview, null);
} else {
v = convertView;
}
TextView text = (TextView) v.findViewById(R.id.textView1);
text.setText("Image Text");
ImageView icon = (ImageView) v.findViewById(R.id.imageView1);
icon.setImageResource(mThumbIds[position]);
return v;
}
}
2-я Активность
ImageView button;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
button=(ImageView)findViewById(R.id.imageView1);
Bundle extra=getIntent().getExtras();
if(extra!=null)
{
Bitmap bitmap = (Bitmap) getIntent().getParcelableExtra("bitmap");
button.setImageBitmap(bitmap);
}
}