要实现一个功能
单击一个listView 的列表项, 进入详情页面, 跳转的过程中要传递一个 Bitmap
- // ListView的单击事件
- @Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- super.onListItemClick(l, v, position, id);
- //产品图像
- ImageView imageView = ((ImageView)layout.findViewById(R.id.product_img));
- //Bitmap productImg = imageView.getDrawingCache();//??? 返回null
- BitmapDrawable mDrawable = (BitmapDrawable) imageView.getDrawable();
- Bitmap productImg = mDrawable.getBitmap();
- //传递
- Bitmapintent.putExtra("productImg", productImg);
注意1 productImg = imageView.getDrawingCache();//??? 返回null
正确的取法是:
BitmapDrawable mDrawable = (BitmapDrawable) imageView.getDrawable();
Bitmap productImg = mDrawable.getBitmap();
- 接收 :productImg = (Bitmap) bundle.get("productImg");