2010-09-02 108 views
1

我是android dev的新手。我想添加圖像ListViewthis在ListView中添加圖像

有什麼想法?

+3

看看這裏:http://stackoverflow.com/questions/459729/how-to-display-list-的圖像功能於列表視圖功能於安卓 – slhck 2010-09-02 10:41:36

回答

1

this tutorial中,您可以看到如何定義自定義ListView。這應該可以幫助你實現你自己的解決方案。

0

Here's通過重構列表適配器代碼來高效實現複雜列表視圖。

0

下面是代碼,這將幫助ü出在列表視圖中添加圖像

public class ItemsList extends ListActivity { 

private ItemsAdapter adapter; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.items_list); 

    this.adapter = new ItemsAdapter(this, R.layout.items_list_item, ItemManager.getLoadedItems()); 
    setListAdapter(this.adapter); 
} 

private class ItemsAdapter extends ArrayAdapter<Item> { 

    private Item[] items; 

    public ItemsAdapter(Context context, int textViewResourceId, Item[] items) { 
      super(context, textViewResourceId, items); 
      this.items = items; 
    } 

    @Override 
    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.items_list_item, null); 
      } 

      Item it = items[position]; 
      if (it != null) { 
        ImageView iv = (ImageView) v.findViewById(R.id.list_item_image); 
        if (iv != null) { 
          iv.setImageDrawable(it.getImage()); 
        } 
      } 

      return v; 
     } 
    } 

    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) { 
     this.adapter.getItem(position).click(this.getApplicationContext()); 
    } 
}