2011-11-11 20 views
1
public class GalleryImageAdapter extends BaseAdapter{ 

    private Activity activity; 
    private ArrayList<String> listOfImages; 
    public ImageLoader imageLoader; 


    public GalleryImageAdapter(Activity a, ArrayList<String> listOfImages){ 
     activity = a; 
     this.listOfImages = listOfImages; 
     imageLoader=new ImageLoader(activity.getApplicationContext()); 
    } 

    @Override 
    public int getCount() { 
     return listOfImages.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return listOfImages.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup viewGroup) { 
     View v = convertView; 


     if (v == null) { 
      LayoutInflater vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      v = vi.inflate(R.layout.gallery_layout, null); 

     } 



     final String url = listOfImages.get(position); 


     ImageView galleryImage = (ImageView) v.findViewById(R.id.galleryImage); 
     imageLoader.DisplayImage(url, activity, galleryImage); 


     v.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT,200)); 
     return v; 
    } 


    public float getScale(boolean focused, int offset) { 
     /* Formula: 1/(2^offset) */ 
      return Math.max(0, 1.0f/(float)Math.pow(2, Math.abs(offset))); 
     } 

} 

私はここにギャラリーアダプターを持っています。イメージが変更されたときを検出してイメージの位置番号を取得できるようにするために利用できる方法があるかどうか疑問に思っています。Androidギャラリーウィジェット:画像変更のトリガー方法

+0

画像が中央に移動して選択されたことを意味しますか?その場合は、ギャラリーでsetOnItemSelectedListener()を使用できます。 –

答えて

3

ポジションはあなたの後です。 AdapterView.OnItemSelectedListenerを参照してください。

mGallery.setOnItemSelectedListener(new OnItemSelectedListener() { 

     @Override 
     public void onItemSelected(AdapterView<?> parent, View v, 
       int position, long id) { 
      // position will display it's place in the adapter 
     } 

     @Override 
     public void onNothingSelected(AdapterView<?> arg0) { 
      // Do nothing 
     } 
    }); 
関連する問題