Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SimpleCrsorAdapter在我滚动时加载错误的图像_Android_Imageview_Simplecursoradapter - Fatal编程技术网

Android SimpleCrsorAdapter在我滚动时加载错误的图像

Android SimpleCrsorAdapter在我滚动时加载错误的图像,android,imageview,simplecursoradapter,Android,Imageview,Simplecursoradapter,我搜索了很多,但我的问题似乎很具体,即使它很简单。但我无法找出它 我有一个带有自定义ViewBinder的SimpleCursorAdapter,可以从URL在ImageView中显示图像 我的项目模板: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_

我搜索了很多,但我的问题似乎很具体,即使它很简单。但我无法找出它

我有一个带有自定义ViewBinder的SimpleCursorAdapter,可以从URL在ImageView中显示图像

我的项目模板:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:orientation="horizontal">

 <ImageView
    android:id="@+id/postImage"
    android:layout_width="86dp"
    android:layout_margin="8dp"
    android:layout_height="48dp"
    android:background="#FFFFFF"
    android:src="@drawable/defaultImg"
    android:scaleType="fitCenter"  />

<TextView android:id="@+id/textinfos1"
     android:textSize="14sp"
     android:layout_margin="8dp"
     android:layout_width="match_parent"
     android:textColor="@android:color/white"
     android:layout_height="wrap_content"
     />
 </LinearLayout>
如果我的视图是R.id.postImage,我会执行一个异步调用,将我的imgUrl转换为一个可绘制的,这很好

当我在列表上滚动时出现问题。新项目已加载,但在1/2秒内,较新的ImageView会显示弹出的ImageView的图像。在此之后,将显示权限图像

更简单的版本,当我向下滚动时,从屏幕顶部消失的图像将显示在底部的新图像视图中。这也会以另一种方式发生。滚动到顶部,显示消失的人

我想在ImageView上设置一个标记并进行检查,但我不知道如何检查

有没有办法将加载的图像保存在一种缓存中? 我是否需要创建自定义游标适配器来提供此机制?还是我做错了什么

非常感谢

编辑1 这是我的下载图像任务:

public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    ImageView imageView;

    public DownloadImageTask(ImageView imageView) {
        this.imageView = imageView;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap imgBitmap = null;
        InputStream in = null;
        try {
            in = new java.net.URL(urldisplay).openStream();
            imgBitmap = BitmapFactory.decodeStream(in);

        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        finally
        {
            try {
                if(in != null)in.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return imgBitmap;
    }

    protected void onPostExecute(Bitmap result) {
        imageView.setImageBitmap(result);
    }
}

弹出是指默认图像吗?您将一个ImageView传递给下载的ImageTask ctor,我假设您稍后将其用于setImageBitmap,对吗?您无法执行此操作,因为项目视图由游标重复使用,而不是默认图像,而是在另一个不再显示的图像视图中替换默认图像的图像。pskink是的,我这样做。但是,我如何在不使用视图的情况下设置图像位图呢?如果我在没有异步任务的情况下设置图像位图,我不会有问题,但它是滞后的,不平滑的。
public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    ImageView imageView;

    public DownloadImageTask(ImageView imageView) {
        this.imageView = imageView;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap imgBitmap = null;
        InputStream in = null;
        try {
            in = new java.net.URL(urldisplay).openStream();
            imgBitmap = BitmapFactory.decodeStream(in);

        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        finally
        {
            try {
                if(in != null)in.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return imgBitmap;
    }

    protected void onPostExecute(Bitmap result) {
        imageView.setImageBitmap(result);
    }
}