我正在使用自定義ArrayAdapter爲了在我的頁面中填充一個ListView。這是該適配器的initation代碼:使用ArrayListAdapter與ListView
public IngredientListAdapter(Context context, int layout_resourceid, ArrayList<RecipeItem> items) {
super(context, layout_resourceid);
this.items = items ;
ctx = context;
}
對此陣列適配器,我通過RecipeItems數組(我ListRecipeItems ListActivity類中)這樣:
iAd = new IngredientListAdapter(this, R.layout.recipeitem_row, recipe.Ingredients);
this.setListAdapter(iAd) ;
然而,我發現, ListView沒有被填充,儘管recipe.Ingredients ArrayList肯定被填充正確。
iAd.items.getCount()的檢查確認項目在那裏。 我可以通過使用.add()例如手動添加每個項目來填充ListView。
for(int i=0;i<recipe.Ingredients.size();i++)
{
iAd.add(recipe.Ingredients.get(i));
}
我的理解是,在初始化時將完整數組傳遞給ArrayAdapter會自動填充該ListView。但是,似乎Adapater的getView方法永遠不會被調用。
任何人都可以對此行爲有所瞭解嗎?我對android和java很新,所以我可能錯過了一些明顯的東西。
非常感謝 尼克
奇妙的,那工作!我知道這很簡單,我錯過了。 謝謝丹:) – Nick 2010-08-17 16:39:07