Android ListView消失图像
我有一个列表视图,我正在为手机上的每个联系人填充姓名和图像(如果有)。当应用程序刚开始加载时,这可以正常工作,但一旦我开始在ListView中滚动,原来正确的图像就会消失。我能想到的唯一一件事是,这些资源被使用了,然后一旦它们从屏幕上滚下来就被销毁了,但我不知道如何保持它们的存在 我正在遍历所有联系人并存储姓名,并使用contacts contract.contacts.openContactPhotoInputStream(context.getContentResolver(),photoUri);检索联系人图像的输入流。然后,在我的自定义ArrayAdapter中,我使用Drawable.createFromStream()为我的ListView项的ImageView设置图像 谢谢 编辑: 根据要求,这里是我的getView方法Android ListView消失图像,android,image,listview,android-2.2-froyo,Android,Image,Listview,Android 2.2 Froyo,我有一个列表视图,我正在为手机上的每个联系人填充姓名和图像(如果有)。当应用程序刚开始加载时,这可以正常工作,但一旦我开始在ListView中滚动,原来正确的图像就会消失。我能想到的唯一一件事是,这些资源被使用了,然后一旦它们从屏幕上滚下来就被销毁了,但我不知道如何保持它们的存在 我正在遍历所有联系人并存储姓名,并使用contacts contract.contacts.openContactPhotoInputStream(context.getContentResolver(),photoU
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;
}
一旦你从InputStream中读取了数据,你就到达了它的末尾,如果不向提供者请求一个新的InputStream,你就不能重新读取它。你能在你的帖子中包含适配器getView()方法的代码吗?谢谢,我今天下午就知道了!我将输入流读入位图,效果很好。