从 Fragment 中的自定义 ListAdapter 和 ListView 设置位图图像视图
Setting a Bitmap Imageview from Custom ListAdapter and ListView in Fragment
我有一个 Fragment,其中 listview 有一个按钮调用一个带有一些信息的警报对话框,上面是 imageView,它需要用相机捕获的图像设置我该怎么做
采取的步骤
在 ListViewAdapter 中 class
private void camerafirstOnClickEventHandler(int num) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUriLandAdapter = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUriLandAdapter);
if (num == 2) {
((Activity) con).startActivityForResult(intent, CAMERA_REQ2);
}
}
public void previewCapturedImage(ImageView imageView, Uri uri) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
final Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath(),
options);
imageView.setImageBitmap(bitmap);
arrBitmaps.add(bitmap);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
在片段中 Class
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
landAdapter.previewCapturedImage(landAdapter.uprootImage,landAdapter.fileUriLandAdapter);
}
但是没有调用 PreviewCapturedImage
创建接口
public interface onGetImage{
void onItemClicked();
}
在您的 Fragment 上实现接口 Class 并使用您的适配器对象设置侦听器。
片段Class:
@Override
public void onItemClicked(){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUriLandAdapter = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUriLandAdapter);
startActivityForResult(intent, CAMERA_REQ2);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
landAdapter.previewCapturedImage(landAdapter.uprootImage,landAdapter.fileUriLandAdapter);
}
列表视图适配器:
onGetImage callback;
public void setListener(onGetImage callback){
this.callback=callback;
}
private void camerafirstOnClickEventHandler(int num) {
if (num == 2) {
callback.onItemClicked();
}
}
我有一个 Fragment,其中 listview 有一个按钮调用一个带有一些信息的警报对话框,上面是 imageView,它需要用相机捕获的图像设置我该怎么做
采取的步骤
在 ListViewAdapter 中 class
private void camerafirstOnClickEventHandler(int num) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUriLandAdapter = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUriLandAdapter);
if (num == 2) {
((Activity) con).startActivityForResult(intent, CAMERA_REQ2);
}
}
public void previewCapturedImage(ImageView imageView, Uri uri) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
final Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath(),
options);
imageView.setImageBitmap(bitmap);
arrBitmaps.add(bitmap);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
在片段中 Class
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
landAdapter.previewCapturedImage(landAdapter.uprootImage,landAdapter.fileUriLandAdapter);
}
但是没有调用 PreviewCapturedImage
创建接口
public interface onGetImage{
void onItemClicked();
}
在您的 Fragment 上实现接口 Class 并使用您的适配器对象设置侦听器。 片段Class:
@Override
public void onItemClicked(){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUriLandAdapter = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUriLandAdapter);
startActivityForResult(intent, CAMERA_REQ2);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
landAdapter.previewCapturedImage(landAdapter.uprootImage,landAdapter.fileUriLandAdapter);
}
列表视图适配器:
onGetImage callback;
public void setListener(onGetImage callback){
this.callback=callback;
}
private void camerafirstOnClickEventHandler(int num) {
if (num == 2) {
callback.onItemClicked();
}
}