我正在尝试回收gridview项目,因为当前的解决方案可以工作,但是滞后并且占用资源。但是,我无法弄清楚如何。 Android开发者网站的例子对我不起作用。
我的getview()方法:
public View getView(int position, View paramView, ViewGroup paramViewGroup) {
long starttime = System.currentTimeMillis();
View localView = MMWeb.this.getLayoutInflater().inflate(R.layout.grid_item, null);
TextView localTextView = (TextView)localView.findViewById(2131034115);
ImageView localImageView = (ImageView)localView.findViewById(2131034114);
cItem = items.get(position);
cItem.add(Integer.toString(position));
localTextView.setText(getItemName());
Bitmap localBitmap = d.getImage(cItem.get(3), cItem.get(2));
localImageView.setImageBitmap(localBitmap);
Common.toLog("getView took "+ (System.currentTimeMillis() - starttime) + " ms");
return localView; }
有人能指出我正确的方向吗?如何解决这个问题的任何建议将不胜感激!
答案 0 :(得分:0)
只需使用paramView
,这是适配器视图传递的可重用视图,因为它在屏幕上不再可见。
if (paramView == null) {
// inflate a new view into paramView.
paramView = MMWeb.this.getLayoutInflater().inflate(R.layout.grid_item, null);
}
// fill the paramView
TextView localTextView = (TextView)paramView .findViewById(2131034115);
ImageView localImageView = (ImageView)paramView .findViewById(2131034114);
cItem = items.get(position);
cItem.add(Integer.toString(position));
localTextView.setText(getItemName());
Bitmap localBitmap = d.getImage(cItem.get(3), cItem.get(2));
localImageView.setImageBitmap(localBitmap);
return paramView;