我正在查询SQLite数据库并将数据放入列表视图。其中一个数据库行包含一个图像Url字段(也可以是Uri)。来自使用自定义光标适配器闪烁url的图像
图像被加载,因为他们应该,但只要我滚动列表所有的图像开始闪烁,一些正在改变的地方或显示在不同的地方。
我已经明白,这种行为发生是因为列表视图重复使用滚动行,但我不知道如何解决这种行为。此外,我不能在这个项目中使用像毕加索这样的外部库。
这里是我的适配器代码:
public class FilmsListCustomAdapter extends CursorAdapter {
private LayoutInflater cursorInflater;
public FilmsListCustomAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
cursorInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView filmTitle = (TextView) view.findViewById(R.id.filmListTitle);
TextView filmScore = (TextView) view.findViewById(R.id.filmListScore);
ImageView filmImage = (ImageView)view.findViewById(R.id.filmListPoster);
ImageView filmSeen = (ImageView)view.findViewById(R.id.filmListSeen);
String title = cursor.getString(cursor.getColumnIndex("title"));
String score = cursor.getString(cursor.getColumnIndex("score"));
String url = cursor.getString(cursor.getColumnIndex("url"));
int seen = cursor.getInt(cursor.getColumnIndex("seen"));
if(Patterns.WEB_URL.matcher(url).matches()){
LoadImage loadImage = new LoadImage(context,filmImage);
loadImage.execute(url);
}
else{
Bitmap bmp = BitmapFactory.decodeFile(url);
CamImage camImage = new CamImage(context,Uri.parse(url));
Bitmap rotetedIm = camImage.rotateCamImage(bmp,url);
if(rotetedIm!=null){filmImage.setImageBitmap(Bitmap.createScaledBitmap(rotetedIm, 850, rotetedIm.getHeight(), false));}
else{filmImage.setImageResource(R.drawable.no_poster);}
}
GlobalMethods methods = new GlobalMethods(context);
filmTitle.setTypeface(methods.getWalkFont());
filmTitle.setText(title);
filmScore.setText(score);
if(seen==1){filmSeen.setImageResource(R.drawable.eye);}
else{filmSeen.setImageResource(0);}
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
return cursorInflater.inflate(R.layout.film_row, viewGroup, false);
}
}
我不明白你为什么不想使用毕加索的libabry。使用Picasso或Glide库来显示具有存储图像功能的图像,因此无需在列表视图中下载图像。这里是毕加索的链接:http://square.github.io/picasso/和For Glide:https://github.com/bumptech/glide – Janak
它不是我不想。这是一个学校项目,他们要求我不会使用外部库。 –