2017-05-11 3 views
0

에 액세스 할 수있는 방법이 내 객체내가 LayoutInflater에서 이미지 뷰

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 기능입니다.

공공 무효 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 
    } 
} 

, 이미지 뷰가 null보기에서 비트 맵 이미지에 액세스 할 수 있습니다 .. 내가 R.id에 이미지를 공유 할

을 .image_preview 그래서 어떻게 R.id.image_preview 이미지에 액세스 할 수 있습니까?

답변

0

왜 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); 
     ... 
    } 
} 
+0

mImageView = (이미지 뷰) getActivity() getLayoutInflater() 팽창 (R.layout.image_fullscreen_preview, NULL) .findViewById (R.id.image_preview); Uri bmpUri = getLocalBitmapUri (mImageView); böpUri은 null입니다. – jancooth