1
這是我的GridView自定義適配器類。我試圖通過一次調用佈局壓縮器來優化網格滾動的速度,並使用視圖持有者,但現在滾動速度非常慢。GridView非常緩慢滾動
private Context mContext;
private final String[] web;
private final int[] Imageid;
public CustomGrid(Context c, String[] web, int[] Imageid) {
mContext = c;
this.Imageid = Imageid;
this.web = web;
}
class MyViewHolder {
ImageView imageView;
TextView textView;
MyViewHolder(View v) {
imageView = (ImageView) v.findViewById(R.id.grid_image);
textView = (TextView) v.findViewById(R.id.grid_text);
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid = convertView;
MyViewHolder viewHolder;
if (grid == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
grid = inflater.inflate(R.layout.grid_single, null);
viewHolder = new MyViewHolder(grid);
grid.setTag(viewHolder);
} else {
grid = convertView;
viewHolder= (MyViewHolder) grid.getTag();
}
viewHolder.textView.setText(web[position]);
viewHolder.imageView.setImageResource(Imageid[position]);
return grid;
}