Android 如何访问LayoutFlater imageView

Android 如何访问LayoutFlater imageView,android,android-imageview,layout-inflater,Android,Android Imageview,Layout Inflater,这是我的目标 public Object instantiateItem(ViewGroup container, int position) { layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.image_fullsc

这是我的目标

    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;
    }
这是我的共享函数

在shareItem()上的公共无效{ //从视图中访问位图图像

      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\u预览中共享图像
那么我如何才能访问R.id.image\u预览图像。

为什么不使用类变量来存储ImageView,这样就可以在类中的任何地方使用它呢

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);
         ...
     }
}
mImageView=(ImageView)getActivity().GetLayoutFlater().inflate(R.layout.image\u全屏\u预览,空)。findViewById(R.id.image\u预览);Uri bmpUri=getLocalBitmapUri(mImageView);böpUri为空:(