我有一個ListView,用於填充手機上每個聯繫人的名稱和圖像(如果存在)。這應用程序最初加載時工作正常,但一旦我開始滾動ListView,最初正確的圖像消失。我能想到的唯一的事情就是資源一旦從屏幕上滾下來就被使用,然後被銷燬,但我沒有任何運氣發現如何將它們留在周圍。Android ListView消失圖像
我正在循環所有聯繫人並存儲名稱,並使用ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(),photoUri);檢索聯繫人圖像的InputStream。然後,在我的自定義ArrayAdapter中,我使用Drawable.createFromStream()爲我的ListView項目的ImageView設置圖像。
謝謝!
編輯: 按照要求,這裏是我的getView方法
public View getView(int position, View convertView, ViewGroup parent)
{
LinearLayout contact_view;
//Get the current alert object
ContactInfo contact = getItem(position);
//Inflate the view
if(convertView==null)
{
contact_view = new LinearLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi;
vi = (LayoutInflater)getContext().getSystemService(inflater);
vi.inflate(resource, contact_view, true);
}
else
{
contact_view = (LinearLayout) convertView;
}
//Get the fields to populate from the listitem.xml file
TextView contact_name = (TextView)contact_view.findViewById(R.id.contact_name);
ImageView contact_image =(ImageView)contact_view.findViewById(R.id.contact_image);
//Assign the appropriate data from our alert object above
contact_name.setText(contact.get_name());
if(contact.get_contact_image() != null) {
contact_image.setImageDrawable(Drawable.createFromStream(contact.get_contact_image(), "src"));
} else {
contact_image.setImageResource(R.drawable.dummy_image);
}
return contact_view;
}
您可以在您的帖子中包含適配器getView()方法的代碼嗎? – 2010-11-04 02:18:27