2014-09-10 54 views
1
从数据库中获取图像的URL,并显示图像

我有这样的事情在我MainActivity.javaAndroid的 - 在ImageView的

m_dbmanager.addRow(
       "http://pl.wikipedia.org/wiki/1_stycznia", 
       "1", 
       "http://assets3.parliament.uk/iv/main-large//ImageVault/Images/id_7382/scope_0/ImageVaultHandler.aspx.jpg"); 

月1日的报价是链接,我送在另一个活动的WebView,第二次报价(“1”)是行的名称,最后一个第三个引号是我想要连续显示的图像的url。

这里是我负责与图像交互的代码的一部分。

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.row, null); 
       } 
       Order o = items.get(position); 
       if (o != null) 
       { 
         TextView name = (TextView) v.findViewById(R.id.row_textView); 
         ImageView image_view = (ImageView) v.findViewById(R.id.row_imageView); 


         if (name != null) 
         { 
          name.setText("Name: "+o.getOrderName());        
         } 
         if(image_view != null) 
         { 

          final String thumbail = o.getOrderImage(); //TODO, just trying 
          final String link = o.getOrderLink(); 

          image_view.setOnClickListener(new View.OnClickListener() 

          { 
           public void onClick(View view) 
           {  
            Intent intent = new Intent(MainActivity.this, TemplateActivity.class); 
            intent.putExtra("urlString", link); 
            startActivity(intent); 
           } 
          }); 
         } 
       } 
       return v; 
     } 
    } 

Order class in case someone would like to see

现在 - 我该怎么办,以显示URL的地方对象row_imageView“的addRow指定的图像?

谢谢你在前进,

+1

参见[使用的AsyncTask下载图像](http://jmsliu.com/1431/download-images-在ListView中显示图像 – 2014-09-10 12:15:11

+0

尝试使用https://github.com/thest1/LazyList – 2014-09-10 12:21:21

回答

1

您可以使用Picasso library从一个URL加载图像到一个ImageView的。

下载jar并将其添加到项目的libs文件夹中。然后使用下面的代码从URL中的图像,甚至任何其他资源加载到ImageView的:

Picasso.with(your_context).load(url_of_image).placeholder(R.drawable.icon) 
     .noFade().into(your_imageView); 
+0

嘿,谢谢你 - 从所有的链接看起来最简单,我得到了这里。但是,你也许知道为什么这个http://i.imgur.com/bMxsvot.png发生?它建议我将'row_imageView'的类型更改为'Target' – 2014-09-10 13:04:49

+1

加载或不加载?我想你写了其他imageview ..使用'image_view'而不是'row_imageView'。 – DaxeshKhatri 2014-09-10 13:13:16

+0

这是愚蠢的错误,谢谢达克西。有用!好吧,一半:)。 它只显示占位符,而不是我在所有行上的.load()中给出的缩略图。 你有什么想法如何解决这个问题? 如果你有时间并想检查 - 这里是我的整个MainActivity.java http://pastebin.com/xyKWX4TC 对不起,您使用:P – 2014-09-10 13:24:44