这是gridview的代码,它重复显示相同的图像,示例图像2和3一遍又一遍地显示,我该怎么办?
公共类 GridViewImageAdapter 扩展 BaseAdapter { 私有上下文 mContext;
public GridViewImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
//ImageView imageView;
ImageView icon;
if (convertView == null) { // if it's not recycled, initialize some attributes
icon = new ImageView(mContext);
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=inflater.inflate(R.layout.grid_icon, parent, false);
icon=(ImageView)row.findViewById(R.id.album_image);
icon.setScaleType(ImageView.ScaleType.CENTER_CROP);
icon.setImageResource(mThumbIds[position]);
//overlay
View overlay = (View) row.findViewById(R.id.overlay);
int opacity = 100; // from 0 to 255
overlay.setBackgroundColor(opacity * 0x1000000); // black with a variable alpha
FrameLayout.LayoutParams params =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, 600);
params.gravity = Gravity.CENTER;
overlay.setLayoutParams(params);
overlay.invalidate();
return row;
}
return convertView;
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1
};
}