【问题标题】:Setting a Bitmap Imageview from Custom ListAdapter and ListView in Fragment从片段中的自定义 ListAdapter 和 ListView 设置位图 Imageview
【发布时间】:2018-02-23 07:06:53
【问题描述】:

我有一个片段,其中列表视图有一个按钮调用警报对话框,其中包含一些要填充的信息,例如需要使用相机捕获的图像设置的 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 没有被调用

【问题讨论】:

  • 可以用listeners完成
  • 你能把代码贴一下吗

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


【解决方案1】:

创建接口

    public interface onGetImage{
   void onItemClicked();    
    }

在您的片段类上实现接口并使用您的适配器对象设置侦听器。 片段类:

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

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多