2011-08-10 7 views
0

갤러리에 This LoaderImageView을 사용하고 있습니다. 첫 번째는 미리보기 이미지의 격자를 보여줍니다. 사용자가 썸네일 이미지를 클릭하면 그 위치를 얻고 인터넷에서 큰 이미지를 가져 오는 ProgressBar를 보여주는 "LoaderImageView"의 갤러리를 보여주는 새로운 활동으로 넘어갑니다.갤러리 안드로이드에서 다음, 이전보기를 호출하는 방법?

내가 원하는 것은 사용자가 이미지를 선택한 다음 다음, 이전보기를 자동으로 호출해야하는 경우입니다. 실제로 이미지를로드하십시오.

나는 이것을하기 위해 노력하고있다. OnItemSelectedListener();

코드가 있습니다. 그러나 이것은 잘 작동하지 않습니다. 이전에 스크롤했을 때 첫 번째 이미지로 이동합니다. 또한 내 논리대로 작동하지 않습니다.

class BigImageAdapter extends BaseAdapter { 

    DisplayMetrics displayMatrics; 
    HashMap<String, Bitmap> hasLargeBitmap; 
    SharedPhotosData sharedPhotosData; 
    Context mContext; 

    public BigImageAdapter(Context contex, SharedPhotosData photoData) { 

     mContext = contex; 
     displayMatrics = new DisplayMetrics(); 
     hasLargeBitmap = new HashMap<String, Bitmap>(); 
     getWindowManager().getDefaultDisplay().getMetrics(displayMatrics); 
     sharedPhotosData = photoData; 
    } 

    public void recycleAllBitmap() { 
     try { 
      int i = 0; 
      Collection<Bitmap> temp = hasLargeBitmap.values(); 
      for (Bitmap bitmap : temp) { 
       if (bitmap != null) { 
        if (bitmap.isRecycled() == false) { 
         bitmap.recycle(); 
         i++; 
        } 
       } 
      } 
      Log.e("Recycled", "No of images recycled"+i); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

    } 

    public int getCount() { 

     if (sharedPhotosData != null) { 
      if (sharedPhotosData.photoData != null) { 
       return sharedPhotosData.photoData.size(); 
      } else { 
       Log.e(TAG, "sharedData.photoData is null"); 
      } 
     } else { 
      Log.e(TAG, "sharedData is null"); 
     } 

     return 0; 
    } 

    public Object getItem(int position) { 
     return position; 
    } 

    public long getItemId(int position) { 

     return position; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
     View rowView = null; 
     try { 
      MyData curData = null; 
      curData = sharedPhotosData.photoData.get(position); 
      if (convertView == null) { 
       String imagePath = Environment.getExternalStorageDirectory().toString() + SMConstants.FILE_PATH_BASE 
         + SMConstants.S3Folders.PHOTO + curData.getLargeURLLocalPath() + "/" + SMConstants.FILE_NAME_PREFIX 
         + curData.getFileName(); 
       if (hasLargeBitmap.containsKey(imagePath) == false) { 
        rowView = new AsynImageView(hasLargeBitmap, PhotoGalleryActivity.this, curData); 
       } else { 
        Bitmap image = hasLargeBitmap.get(imagePath); 

        ImageView mImageView = new ImageView(mContext); 
        mImageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 
          Gravity.CENTER)); 
        mImageView.setImageBitmap(image); 
        mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 
        mImageView.setAdjustViewBounds(true); 
        rowView = mImageView; 
       } 
       rowView.setLayoutParams(new Gallery.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, 
         android.view.ViewGroup.LayoutParams.FILL_PARENT)); 
      } else { 
       rowView = convertView; 
      } 

     } catch (Exception e) { 
      Log.e("Exception", "LargeSlideShow.GetView Message = " + e); 
      e.printStackTrace(); 
     } catch (Error e) { 
      Log.e("Error", "LargeSlideShow.GetView Message = " + e); 
      e.printStackTrace(); 
     } 
     return rowView; 
    } 
} 

@Override 
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) { 
    try { 

     if (position - 1 >= 0) { 
      myGalleryForLargeImage.setSelection((position - 1)); 
     } 
     if (position + 1 < size) { 
      myGalleryForLargeImage.setSelection((position + 1)); 
     } 
    } catch (Exception e) { 
     Log.e(TAG, "Exception = " + e.toString()); 
     e.printStackTrace(); 
    } 
} 

@Override 
public void onNothingSelected(AdapterView<?> arg0) { 

} 

답변

0

확인. 나는 "myGalleryForLargeImage.setSelection ((position - 1));"대신 " 그것은 끝내야합니다. 지금은 View를 얻으 려하고 getView() 메소드가 호출되면 이미지 요청을 시작합니다.

@Override 
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) { 
    try { 

     if (position - 1 >= 0) { 
      bigImageAdapter.getView(position-1, null, myGalleryForLargeImage); 
     } 
     if (position + 1 < size) { 
      bigImageAdapter.getView(position+1, null, myGalleryForLargeImage); 
     } 
    } catch (Exception e) { 
     Log.e(TAG, "Exception = " + e.toString()); 
     e.printStackTrace(); 
    } 
} 
관련 문제