2012-02-28 72 views
0
private static final String picpic = "picpic"; 

private ArrayList < HashMap < String, Object>> myBooks; 

myBooks = new ArrayList<HashMap<String,Object>>(); 

HashMap < String, Object> hm; 

hm = new HashMap<String, Object>(); 

drawable=LoadImage("http://www.wauhaha.com/smart/company/album/pic.jpg"); 

hm.put(picpic, drawable); 


myBooks.add(hm); 

final ListView listView = (ListView)findViewById(R.id.list); 

SimpleAdapter adapter = new SimpleAdapter(this, myBooks, R.layout.listbox, new String[]{picpic}, new int[]{R.id.image1}); 


listView.setAdapter(adapter); 
+0

請提前致謝^^ – 2012-02-28 13:05:00

+0

實際上你想要什麼?我認爲你的應用程序中的圖像與列表視圖? – 2012-02-28 13:10:58

+0

http://3.bp.blogspot.com/_C5a2qH8Y_jk/TBQFC3VNHBI/AAAAAAAAAcs/t7bAWJzD2iY/s1600/AndroidList_02.png 我想要一些像上面顯示的url ~~~但我想通過使用URL來放置圖像,而不是R.drawable.launcher somethings like that – 2012-02-28 13:22:28

回答

0

如果你想關鍵是網址然後使用此代碼。

//Declarations 

public Map<String, Object> ImageMap = new WeakHashMap<String, Object>(); 

//Inserting into HashMap 

public void addToHash(String url) 
{ 
    ImageMap.put(url,LoadImage(url)); 
} 

// Get from HashMap 
public Object getImageFromHash(String url) 
{ 
    ImageMap.get(url); 
} 

EDITED 您可以使用薩米爾, 你需要使用ImageLoader.java,ImageCache.java,FileCache.java和Utils.java

給出的解決方案爲您的適配器

public class LazyAdapter extends BaseAdapter { 

    private Activity activity; 
    private ArrayList<String> urls; 
    private static LayoutInflater inflater=null; 
    public ImageLoader imageLoader; 

    public LazyAdapter(Activity a, ArrayList<String> u) { 
     activity = a; 
     urls=u; 
     inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     imageLoader=new ImageLoader(activity.getApplicationContext()); 
    } 

    public int getCount() { 
     return data.size(); 
    } 

    public Object getItem(int position) { 
     return position; 
    } 

    public long getItemId(int position) { 
     return position; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
     View vi=convertView; 
     if(convertView==null) 
      vi = inflater.inflate(R.layout.listbox, null); 

     ImageView thumb_image=(ImageView)vi.findViewById(your.imageview.id); // thumb image 

     imageLoader.DisplayImage(urls.get(position), thumb_image); 
     return vi; 
    } 
} 
+0

SimpleAdapter adapter = new SimpleAdapter(this,myBooks,R.layout.listbox,new String [] {picpic},new int [] {R.id .image1}); *我如何聲明適配器,因爲我嘗試你的解決方案,並沒有生效,我仍然無法獲得圖像~~~ – 2012-02-28 13:38:14

+0

使用可以使用薩米爾的解決方案看我編輯的答案 – 2012-02-28 14:00:04