从Fragment中的Custom ListAdapter和ListView设置位图Imageview

时间:2018-02-23 07:06:53

标签: android listview android-fragments popup android-alertdialog

我有一个片段,其中listview有一个按钮,调用一个带有一些信息填充的alertdialog,就像是需要使用Camera Captured image设置的imageView我该怎么做

采取的步骤

ListViewAdapter类中的

 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();
        }
    }

在片段类

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        // if the result is capturing Image
landAdapter.previewCapturedImage(landAdapter.uprootImage,landAdapter.fileUriLandAdapter);


}

但是没有调用PreviewCapturedImage

1 个答案:

答案 0 :(得分:0)

创建一个界面

    public interface onGetImage{
   void onItemClicked();    
    }

在Fragment Class上实现接口,并使用适配器对象设置侦听器。 FragmentClass:

@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);


}

ListViewAdapter:

onGetImage callback;
public void setListener(onGetImage callback){
this.callback=callback;
}

private void camerafirstOnClickEventHandler(int num) {

        if (num == 2) {
            callback.onItemClicked();
        }

    }