如何获得setImageResource方法的String类型? [英] How to get String type in setImageResource method?

查看:876
本文介绍了如何获得setImageResource方法的String类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code:holder.icon.setImageResource(current.imageUrl);这里的图片网址是字符串被宣布。但setImageResource只需INT。谁能给我提供一个解决方案是如何得到一个字符串或者是有可用的电气特性的方法呢?

My code: holder.icon.setImageResource(current.imageUrl); here the imageUrl is been declared in String. But setImageResource takes only int. Can anyone provide me a solution how to get a string or is there anyother method available for it?

推荐答案

我觉得你是从互联网上获取的图像。

I think u are fetch the image from internet.

 private Bitmap getBitMapFromUrl( String imageuri){
        HttpURLConnection connection=null;

        try {
            URL url=new URL(imageuri);
            connection= (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream is=connection.getInputStream();
            Bitmap mybitmap=BitmapFactory.decodeStream(is);
            return mybitmap;

        } catch (MalformedURLException e) {
            e.printStackTrace();
            return null;
        }}

传递字符串值,并返回位图。

pass the string value and return the bitmap.

enter code here

holder.icon.setBitmapImage(getBitmapFromUrl());

holder.icon.setBitmapImage(getBitmapFromUrl());

这篇关于如何获得setImageResource方法的String类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆