java - 如何在 ListView 中无延迟地从网络下载图像?

标签 java android imageview android-arrayadapter listadapter

我有一个 ListAdapter,其中包含一堆从互联网下载的图像。当我上下滚动时,性能似乎受到了影响,并且事情变得不稳定。我该如何解决这个问题?

@Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.message_row, null);
            }

            STMessage aMessage = messages.get(position);

            if (aMessage != null) {
                TextView usernameTextView = (TextView) v.findViewById(R.id.usernameTextView);
                TextView bodyTextView = (TextView) v.findViewById(R.id.bodyTextView);
                TextView dateTextView = (TextView) v.findViewById(R.id.dateTextView);
                ImageView avatarImageView = (ImageView)v.findViewById(R.id.avatarImageView);

                if (usernameTextView != null) {
                    usernameTextView.setText(Html.fromHtml(aMessage.getUser_login()));
                }
                if (bodyTextView != null) {
                    bodyTextView.setText(aMessage.getBody());

                    //linkify urls
                    Linkify.addLinks(bodyTextView, Linkify.WEB_URLS);


                    //linkify symbols
                    Pattern symbolMatcher = Pattern.compile("/(?:^|\\s|[\\.(\\+\\-\\,])(?:\\$?)\\$((?:[0-9]+(?=[a-z])|(?![0-9\\.\\:\\_\\-]))(?:[a-z0-9]|[\\_\\.\\-\\:](?![\\.\\_\\.\\-\\:]))*[a-z0-9]+)/i");
                    String symbolURL =    "content://com.stocktwits.activity/symbol/";
                    Linkify.addLinks(bodyTextView, symbolMatcher, symbolURL);
                }
                if (dateTextView != null) {
                    dateTextView.setText(aMessage.getUpdated_at());
                }

                if (avatarImageView != null) {
                    imageDownloader.download(aMessage.getAvatar_url(), avatarImageView);
                }
            }

            return v;
        }

最佳答案

使用图像延迟加载 - Lazy load of images in ListView

关于java - 如何在 ListView 中无延迟地从网络下载图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5762271/

相关文章:

java - 如何从图像中删除宽度未知的边框

java - 以编程方式检索 MAC 地址 - Android

java - Android arraylist<String> 转为单个字符串

xcode - 如何更改 ImageView 的图像?

java - 设置图像资源

android - 图像缩放的正确变换

java - 使用递归对数字进行阶乘

java - 改造入队不起作用但执行工作

android - 加载 Bitmap 后释放内存

java - 为什么我无法执行获取 java.lang.IllegalStateException 的 Activity 的方法?