我怎样才能访问 LayoutInflater imageView

How can i access to LayoutInflater imageView

这是我的对象

    public Object instantiateItem(ViewGroup container, int position) {

        layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = layoutInflater.inflate(R.layout.image_fullscreen_preview, container, false);

        ImageView imageViewPreview = (ImageView) view.findViewById(R.id.image_preview);

        Image image = images.get(position);

        Glide.with(getActivity()).load(image.getLarge())
                .thumbnail(0.5f)
                .crossFade()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imageViewPreview);

        container.addView(view);

        return view;
    }

这是我的 onShare 功能。

public void onShareItem() { // 从视图中获取位图图像

      ImageView  i = (ImageView) getActivity().getLayoutInflater().inflate(R.layout.image_fullscreen_preview,null).findViewById(R.id.image_preview);

    //imageViewPreview = (ImageView) viewPager.findViewById(R.id.image_preview);
    // Get access to the URI for the bitmap
    Uri bmpUri = getLocalBitmapUri(imageViewPreview);
    if (bmpUri != null) {
        // Construct a ShareIntent with link to image
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
        shareIntent.setType("image/*");
        // Launch sharing dialog for image
        startActivity(Intent.createChooser(shareIntent, "Share Image"));
    } else {
        // ...sharing failed, handle error
    }
}

当我调试应用程序时,imageview 为空..

我想在 R.id.image_preview 中分享图片 那么我怎样才能访问 R.id.image_preview 图片。

你为什么不使用一个 class 变量来存储 ImageView,这样你就可以在 class 中的任何地方使用它?

private ImageView mImageView;

public Object instantiateItem(ViewGroup container, int position) {

    layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = layoutInflater.inflate(R.layout.image_fullscreen_preview, container, false);

    mImageView = (ImageView) view.findViewById(R.id.image_preview);
    ...
}

public void onShareItem() {  
    if (mImageView != null) {
         Uri bmpUri = getLocalBitmapUri(imageViewPreview);
         ...
     }
}