在列表视图滚动期间,首先显示错误的图像,然后显示正确的图像

2024-04-07

I am using listview with images in my application.But whenever I scroll the list the wrong images are shown first and then the correct images are displaying.I dont know why it is happening like this.I think already loaded images are displaying until the position is set. Here is my adapter class,please help me where I am going wrong

  public class MySimpleArrayAdapter extends ArrayAdapter<String> {
    private Activity context;
    ArrayList<String> namear,msgar,idar,profimage,postimage,commentsnum,objectid,urlString;
  ImageLoader imageLoader;
  Bitmap[] bitdata;

  public MySimpleArrayAdapter(Activity c,int i,ArrayList<String> postpic, ArrayList<String> names,ArrayList<String> msg,ArrayList<String> id,ArrayList<String> proimg,Bitmap[] bit,ArrayList<String> comment,ArrayList<String> objid,ArrayList<String> web) {

      super(c, i, names);
    Log.e("adapter","adap");
    this.context = c;
    this.namear = names;
    this.msgar = msg;
    this.idar = id;
    this.profimage=proimg;
    this.postimage=postpic;
    this.bitdata=bit;
    this.commentsnum=comment;
    this.objectid=objid;
    this.urlString=web;
   this.imageLoader = new ImageLoader(context);
  }

  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
  View rowView=convertView;
  ViewHolder holder = new ViewHolder();
      if(convertView == null) {
  LayoutInflater inflator = getLayoutInflater();
  rowView = inflator.inflate(R.layout.walldata, null);

  holder.name1 = (TextView) rowView.findViewById(R.id.name);
  holder.message1 = (TextView) rowView.findViewById(R.id.msg);
  holder.profimg= (ImageView) rowView.findViewById(R.id.profile_pic);
  holder.postimg= (ImageView) rowView.findViewById(R.id.picpost);
  holder.comments = (TextView) rowView.findViewById(R.id.comment);
  rowView.setTag(holder);
     Log.e("user",idar.get(position));
      }
      else
         {
          holder = (ViewHolder) rowView.getTag();
         }
    Log.e("adapter","adap");
    holder.name1.setText(namear.get(position));
    if(msgar.get(position)!=""){
        holder.message1.setText(msgar.get(position));

    }
    else
    {
        holder.message1.setVisibility(View.GONE);
    }
    if(!postimage.get(position).equals(""))
    {try{
         imageLoader.DisplayImage(postimage.get(position).replace(" ", "%20"), holder.postimg) ;

    }
    catch(Exception e){
        e.printStackTrace();
    }
    }
    else
    {
         holder.postimg.setVisibility(View.GONE);
    }
    try{
      imageLoader.DisplayImage(profimage.get(position).replace(" ", "%20"), holder.profimg) ;
    }
    catch(Exception e){
       e.printStackTrace();
    }

    holder.comments.setText(commentsnum.get(position)+"\t"+"Comments");
    holder.comments.setOnClickListener(new OnClickListener() {


        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent myintent=new Intent(Wall.this,Comments.class);
            myintent.putExtra("name", namear.get(position));
            myintent.putExtra("profimg", profimage.get(position));
            myintent.putExtra("message", msgar.get(position));
            myintent.putExtra("postpic", postimage.get(position));
            myintent.putExtra("objectid", objectid.get(position));
            myintent.putExtra("commentsnum",commentsnum.get(position));
            myintent.putExtra("webservice", urlString.get(position));
            startActivity(myintent);

        }
    });

    return rowView;
  }

}
public class ViewHolder{
    TextView name1, message1,comments;
    ImageView profimg,postimg;
}

确保在 getView 方法中尽早将 ImageView 中的图像设置为 null。由于 ListView 重复使用列表项,因此旧列表项将一直显示,直到设置新列表项为止。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在列表视图滚动期间,首先显示错误的图像,然后显示正确的图像 的相关文章

随机推荐

  • 更改 MVC3 索引视图中的顺序

    想要有可点击的列标题 例如点击 TagCode 一次 它会按该顺序排序 然后再次反转 号码也一样 使用 MVC3 Razor 和 LightSpeed ORM 我知道网格例如http mvccontrib codeplex com http
  • Bootstrap 3 Datepicker v4 - 设置默认日期

    我正在使用这个日期时间选择器http eonasdan github io bootstrap datetimepicker http eonasdan github io bootstrap datetimepicker 在我的编辑表格中
  • 运行时无命令输出:'am start -n Error

    当我在 Eclipse 中运行应用程序并单击按钮启动新活动时 我的应用程序强制关闭 并收到此错误 null Error Sat Apr 23 19 53 21 CDT 2011 No command output when running
  • MongoDb 和 Nodejs SSL/安全连接

    我如何通过ssl连接mongoDB和nodejs 我正在使用此代码来创建连接 但它不起作用 var Db require mongodb Db var Server require mongodb Server Db connect mon
  • 在类实例之间共享字典内容

    假设我有一个像这样的字典结构 var stocks new Dictionary
  • Xcode 4.4.1 - C 编程 - 添加新的 .c 文件

    我正在 Xcode 4 4 1 中编写 C 程序 一个新项目从 main c 文件开始 这显然是我的主文件 如果我想编写一个不同的程序怎么办 如果我选择 文件 gt 新建文件 Xcode 将在 main c 旁边创建一个新的 c 文件 问题
  • OpenGL ES 2.0 多个程序或多着色器还是什么?它是如何工作的?

    问题 TL DR 我的问题从根本上来说是我不知道 OpenGL ES 2 0 期望我如何编写和使用多个着色器 或者如果甚至建议 期望一个人会这样做 这里的基本问题是 如果我有一个苹果 一块发光的岩石和一个模糊网格 它们都在同一个 3D 世界
  • ffmpeg:“未找到引用的 QT 章节轨道”

    Using ffmpeg将 QuickTime 中的音频替换为 WAV 中的音频 谁知道我为什么会这样Referenced QT chapter track not found Command ffmpeg i video t 25 i a
  • JavaScript 中的文本搜索?

    我有一个页面 其中包含 200 多个采用这种格式的链接 h1 a href somelink Somelink a some text that explain the meaning of the link h1 现在 为了更容易通过此链
  • 生成人类可区分的随机颜色

    我正在尝试在 JavaScript 中随机生成十六进制颜色 然而 生成的颜色几乎无法区分 有办法改善吗 这是我正在使用的代码 function randomColor var allowed ABCDEF0123456789 S while
  • Heroku-未找到 (Python)

    作为一个初学者 我无法再进一步 我正在尝试在heroku上加载python程序 但不知何故总是只出现以下内容 未找到 在服务器上找不到请求的 URL 如果您手动输入 URL 请检查拼写并重试 My logs 2018 02 12T11 33
  • file_get_contents() 与 CURL 等效吗?

    我正在尝试从这样的 url 获取一些 JSON 数据 url http site com search php term search term here result json decode file get contents url 然
  • postgresql 中第一个和最后一个值聚合函数可以正确处理 NULL 值

    我知道有聚合函数可以获取行的最后一个和第一个值PostgreSQL https wiki postgresql org wiki First last 28aggregate 29 我的问题是 它们不能按我的需要工作 我可以使用 postg
  • 根据另一个单元格范围的值创建对一个单元格范围的注释

    我想为一系列单元格创建注释 注释应包含另一个单元格范围的值 这是我到目前为止所拥有的 Private Sub Worksheet Change ByVal Target As Range Dim sResult As String If U
  • CSS3:背景颜色过渡为透明

    我想做一个过渡div that 以 开始background color rgba 242 245 169 1 三秒后 以 结束background color rgba 242 245 169 0 还有 在两场表演之间background
  • PySpark 在嵌套数组中反转 StringIndexer

    我正在使用 PySpark 使用 ALS 进行协作过滤 我原来的用户和项目 ID 是字符串 所以我使用StringIndexer将它们转换为数字索引 PySpark 的 ALS 模型要求我们这样做 安装模型后 我可以获得每个用户的前 3 个
  • 无法在 Python OpenCV v4.20 中使用 SIFT

    我正在使用 OpenCV v4 20 和 PyCharm IDE 我想使用 SIFT 算法 但我收到这个错误 我在互联网上寻找此错误的解决方案 但没有一个对我有帮助 你知道这个错误的解决办法吗 使用 pip 我可以安装至少 3 4 2 16
  • 一个 dataGridView 中的两个实体

    我有两个关联实体 我通过从对象数据源拖放并手动绑定到列表来创建 dataGridView 一个实体的一切工作都很好 是否有可能通过拖放 手动填充来创建一个具有两个实体 Zamow和ZamSkany 的dataGridView 我可以通过视图
  • 无 IDLE 子进程连接

    我是 python 编程新手 想尝试在 IDLE 而不是 OSX 命令行中编辑脚本 但是 当我尝试启动它时 它给出错误 空闲子进程没有建立连接 空闲子进程无法启动子进程或个人防火墙软件阻止连接 我没有配置防火墙 那么问题可能是什么 您可以尝
  • 在列表视图滚动期间,首先显示错误的图像,然后显示正确的图像

    I am using listview with images in my application But whenever I scroll the list the wrong images are shown first and th