在列表视图中滚动列表视图堆大小不断增加,在 Galaxy S3 设备上达到 64MB,应用程序崩溃。
public class GAdapter extends BaseAdapter implements Filterable {
private List<G> list;
private GActivity mContext;
private Drawable attach , text;
private HttpImageManager mHttpImageManager;
private LayoutInflater mInfalotar;
public GAdapter(GActivity context , List<G> list){
this.list = list;
mContext = context;
mInfalotar = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mHttpImageManager = ((GApplication)context.getApplication()).getHttpImageManager();
attach = mContext.getResources().getDrawable(R.drawable.ic_attachment);
text = mContext.getResources().getDrawable(R.drawable.ic_text);
}
public void addContact(VamooseGroup entry){
list.add(entry);
notifyDataSetChanged();
}
public void setGroupList(List<G> g){
list.clear();
datavalues = null;
list.addAll(g);
notifyDataSetChanged();
}
@Override
public int getCount(){
return (list.size()+1);
}
@Override
public Object getItem(int index) {
if(index != list.size())
return list.get(index);
else
return null;
}
@Override
public long getItemId(int index) {
return index;
}
@Override
public int getViewTypeCount() {
return list.size()+1;
}
@Override
public int getItemViewType(int position) {
return position == list.size() ? 1 : 0;
}
@Override
public View getView(int index, View convertview, ViewGroup viewGroup) {
int type = getItemViewType(index);
switch(type){
case 0 :
convertview = mInfalotar.inflate(R.layout.data_listitem , viewGroup, false);
ImageView myimageView = (ImageView)convertview.findViewById(R.id.myImage);
TextView groupname = (TextView)convertview.findViewById(R.id.groupname);
TextView timespam = (TextView)convertview.findViewById(R.id.timeInfo);
TextView msgSender = (TextView)convertview.findViewById(R.id.msgowner);
TextView draft = (TextView)convertview.findViewById(R.id.draft);
ImageView watchIcon = (ImageView)convertview.findViewById(R.id.time);
ImageView attachment = (ImageView)convertview.findViewById(R.id.attachment);
final G g = list.get(index);
String grouppic = g.pic();
if(ImageValidator.validate(grouppic)){
Bitmap bitmap = mHttpImageManager.loadImage(new HttpImageManager.LoadRequest(Uri.parse(grouppic), myimageView));
if (bitmap != null && !bitmap.isRecycled()) {
myimageView.setImageBitmap(bitmap);
}
}
parent.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.select));
groupname.setText("FOO1");
msgbox.setText("FOO2");
groupname.setText("F003");
msgSender.setText("F004");
timespam.setText("F005");
attachment.setBackgroundDrawable(attach);
watchIcon.setBackgroundDrawable(text);
break;
}
return convertview;
}
}
上面的代码是使用列表适配器。我正在使用以下库来显示图像 android-http-image-manager
有人能告诉我为什么位图没有被回收吗?滚动列表视图时堆不断增加,达到 64MB。请提供一个简短的解决方案。