2015-01-13 50 views
0

在我的數據庫中,我有一行存儲來自Internet的圖像的鏈接。 在下面的代碼中,我取了名字並放入了每行的ListView。 現在,KEY_LINK保存圖像的鏈接,我如何將此數組轉換爲位圖,並在ListView中更改每個KEY_NAME?從數據庫到位圖的字符串數組

@SuppressWarnings("deprecation") 
    private void populate(){ 
     Cursor cursor = entry.getAllRows(); 
     String[] from = new String[] {SQLHelper.KEY_NAME, SQLHelper.KEY_LINK}; 
     int[] to = new int[] {R.id.textView1, R.id.textView2}; 
     SimpleCursorAdapter nameAdapter; 
     nameAdapter = new SimpleCursorAdapter(getBaseContext(), R.layout.item_list, cursor, from, to); 
     ListView mylist = (ListView)findViewById(R.id.listView1); 
     mylist.setAdapter(nameAdapter); 



    } 

回答

1

android無法使用url設置imageView。

解決您的情況是

每個URL字符串爲此 1.創建一個HTTPGET請求KEY_LINK,這可能在的AsyncTask 2.獲取連接的結果。如果你確認它返回一個圖像,只需使用這個方法:

那麼你得到所有的圖像在本地,所以你可以通知你的適配器連接到ListView控件。 根據位置覆蓋您的適配器public View getView(int position, View convertView, ViewGroup parent),還更新您的自定義ListView項目(TextView,ImageView)。 有關於如何創建自定義ListView的詳細指南。

http://www.vogella.com/tutorials/AndroidListView/article.html

+0

那是不錯,但我搜索多一點,發現通用圖像裝載機,它可能適合我在這種情況下需要 – he4dless

+0

哇,wonderful.this項目也可以爲他人[通用圖像裝載機(樂於助人https://github.com/nostra13/Android-Universal-Image-Loader) – sakiM

+0

無論如何,我不知道如果我問這裏或提出另一個問題,但我如何從數據庫中獲取內容到一個字符串數組,或者數組列表? – he4dless