ImageView的图像资源

时间:2011-12-02 01:41:54

标签: android

为我的图库设置了几个图像后,我想获取所有已使用的资源ID。 如何在Gallery中获取ImageView的图像资源(int)?

感谢。

1 个答案:

答案 0 :(得分:-1)

public class IndexImageAdapter extends BaseAdapter {

private Context context;  
private int[] panicBuyingImages = {R.drawable.q1 , R.drawable.q2 , R.drawable.q3 , R.drawable.q4};  
public IndexImageAdapter(Context context){   
    this.context = context;  
}  

public int getCount(){   
    return Integer.MAX_VALUE;  
}  

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

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

public View getView(int position, View convertView, ViewGroup parent)  {  
    ImageView i = new ImageView(this.context); 
    i.setImageResource(this.panicBuyingImages[position % panicBuyingImages.length]);  
    i.setScaleType(ImageView.ScaleType.FIT_XY);  
    i.setLayoutParams(new Gallery.LayoutParams(140, 140));  
    return i;  
}  

}