0
我對android編程還很陌生。我遇到了一些問題加載圖像(位圖)到一個ListView。它工作完美,直到我有大約5個圖像加載,然後它重新使用我加載的第一個圖像(從緩存假設)。我嘗試了很多解決方案和位圖採樣,但仍然沒有運氣。這裏是我的代碼:Picasso只加載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()
謝謝你前進!
哇,不能相信解決方案如此簡單。現在奇妙地工作。謝謝! – Sabin