使用适配器传递值以查看

发布于 2024-10-09 11:14:37 字数 401 浏览 0 评论 0原文

我已经实现了(感谢教程)一种显示自定义列表视图的方法,其中包含图像、名称和描述。

我使用 simpleAdapter 将字符串 namedescription 传递给 textViews,以及图像 Id 的 int(图像存储在 R 中) .drawable)到imageView。

问题是:现在我应该设置 ImageViews 以显示从网络下载的图像,所以我有可绘制对象,但我无法从中获取 ID。

如何自定义 simpleAdapter 以将 Drawable 传递给 imageView,并使用 setImageDrawable 方法设置图像?

请说清楚!谢谢

I've implemented (thanks to a tutorial) a way to show a custom listView, with images, names and description.

I used the simpleAdapter to pass the strings name and description to the textViews, and the int of an image's Id (the image is stored in R.drawable) to the imageView.

The problem is: now i should set the ImageViews to display images downloaded from the web, so I have drawables but i can't get IDs from them.

How can i customize the simpleAdapter to pass a Drawable to the imageView, and set the image with the setImageDrawable method?

Please be clear! Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灯下孤影 2024-10-16 11:14:38

试试这个:

http://www.androidpeople.com/android-load -image-from-url-example/

或者从已下载的外部媒体文件加载:

Bitmap myBitmap = BitmapFactory.decodeFile(“/sdcard/myImage.jpg”);

ImageView myImage = (ImageView) findViewById(R.id.imageToShow);

myImage.setImageBitmap(myBitmap);

Try This:

http://www.androidpeople.com/android-load-image-from-url-example/

Or to load from External media files you have already downloaded:

Bitmap myBitmap = BitmapFactory.decodeFile(“/sdcard/myImage.jpg”);

ImageView myImage = (ImageView) findViewById(R.id.imageToShow);

myImage.setImageBitmap(myBitmap);

梦回旧景 2024-10-16 11:14:38

这相当困难...所以我建议使用 CommonsWare 的 ThumbnailAdapter

This is quite difficult... so I would advise to use CommonsWare's ThumbnailAdapter.

撑一把青伞 2024-10-16 11:14:37

我们需要使用viewBinder,如下所示:

        adapter.setViewBinder(new ViewBinder() {

            public boolean setViewValue(View view, Object data,
                            String textRepresentation) {

                    if(data instanceof BitmapDrawable ){
                            ((ImageView)view).setImageDrawable((Drawable)data);
                            return true;
                    }else{
                            return false;
                    }

            }
        });

We need to use the viewBinder, as show here:

        adapter.setViewBinder(new ViewBinder() {

            public boolean setViewValue(View view, Object data,
                            String textRepresentation) {

                    if(data instanceof BitmapDrawable ){
                            ((ImageView)view).setImageDrawable((Drawable)data);
                            return true;
                    }else{
                            return false;
                    }

            }
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文