我想将位图从一个活动传递到适配器。在我的主要活动中,我有以下内容:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data!= null && data.getData() != null){
filePath = data.getData();
try {
//getting image from gallery
Bitmap bitmap1 = MediaStore.Images.Media.getBitmap(this.getContentResolver(), filePath);
Log.i("GRAMP5:","PICK_IMAGE_REQUEST chamado");
}catch(Exception e){
e.printStackTrace();
}
}
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
Log.i("GRAMP6:","REQUEST_TAKE_PHOTO chamado");
setPic();//returns bitmap
Bitmap bitmap2 = setPic();
}
}
我想将bitmap1 / bitmap2传递给适配器。如何实现此功能?提前感谢!
答案 0 :(得分:0)
创建passBitmapData.java
public class passBitmapData{
public Bitmap bitmap;
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
}
从活动中设置位图
public passBitmapData passBitmapData = passBitmapData;
passBitmapData.setBitmap(yourBitmap);
在适配器中获取位图:
public passBitmapData passBitmapData = passBitmapData;
Bitmap Bitmap = passBitmapData.getBitmap();