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