2017-02-21 76 views
0

我正在製作使用JSON請求等電影應用程序所以我有一個列表視圖顯示電影數據,如演員,導演,家長指南,IMDB等。對於在列表視圖把這些數據代碼:如何使用簡單的適配器添加圖像到自定義列表視圖android

ListAdapter adapter = new SimpleAdapter(
       movies.this, contactList, 
       R.layout.list_new, new String[]{"name", "actors", 
       "story", "imrating", "genre","guide", "director"}, new int[]{R.id.title, 
       R.id.actors_txt, R.id.story, R.id.rating, R.id.genre,R.id.parental, R.id.director_txt, R.id.year, R.id.imageView8, R.id.imageView10, R.id.backgroundimg}); 

lv.setAdapter(adapter); 

..這裏是我IMDB圖標的問題,所以它涉及像<imdbicon> 6.2(從JSON),但在imageview的應用程序圖像本身在列表視圖的佈局文件中。

R.id.imageView8, R.id.imageView10, R.id.backgroundimg 

這三個我想在ListView,但我想不出如何

回答

0

可以使SimpleAdapter一個子類,並覆蓋setImageView基於文本獲得的圖像:

ListAdapter adapter = new SimpleAdapter(
       movies.this, contactList, 
       R.layout.list_new, new String[]{"name", "actors", 
       "story", "imrating", "genre","guide", "director"}, new int[]{R.id.title, 
       R.id.actors_txt, R.id.story, R.id.rating, R.id.genre,R.id.parental, R.id.director_txt, R.id.year, R.id.imageView8, R.id.imageView10, R.id.backgroundimg}) { 

    @Override 
    public void setViewImage(ImageView v, String value) { 

     // here you put code to take your "value" string 
     // and get your image, for example using Picasso 
     // or Glide, and putting it in the "v" ImageView. 
    } 
}; 
+0

考慮使用'R.id.imageView8,R.id.imageView10,R.id.backgroundimg',我認爲'setViewImage'與int參數會更加正確 –

+0

感謝它的工作 – John

+0

太棒了!如果你能接受我的回答是正確的,我將不勝感激。 –

相關問題