【发布时间】:2015-04-19 05:43:24
【问题描述】:
我对 android 编程相当陌生。我在将图像(位图)加载到 ListView 时遇到了一些问题。它完美地工作,直到我加载了大约 5 个图像,然后它重用了我加载的第一个图像(假设来自缓存)。我尝试了很多解决方案和位图采样,但仍然没有运气。这是我的代码:
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
view = getLayoutInflater().inflate(R.layout.listview_item, parent, false);
Contact currentContact = Contacts.get(position);
TextView name = (TextView) view.findViewById(R.id.contactName);
name.setText(currentContact.getName());
TextView phone = (TextView) view.findViewById(R.id.phoneNumber);
phone.setText(currentContact.getPhone());
TextView email = (TextView) view.findViewById(R.id.email);
email.setText(currentContact.getEmail());
TextView address = (TextView) view.findViewById(R.id.cAddress);
address.setText(currentContact.getAddress());
Context mContext = getApplicationContext();
File file = mContext.getDir("imageDir", Context.MODE_PRIVATE);
String path = "file:" + file.getPath() + "/" + currentContact.getImage() + ".png";
ImageView contactListImage = (ImageView) view.findViewById(R.id.contactListImage);
Picasso.with(getApplicationContext())
.load(path)
.centerInside()
.fit()
.error(R.drawable.user_2)
.into(contactListImage)
}
return view;
}
我确实尝试过使用
recycleMemoryCache()
在此先感谢您!
【问题讨论】:
标签: android android-layout listview picasso