data = new ArrayList<Item>(10);
data.add(new Item(100, "Sample Food1"));
data.add(new Item(110, "Sample Food2"));
data.add(new Item(120, "Sample Food3"));
data.add(new Item(130, "Sample Food4"));
data.add(new Item(140, "Sample Food5"));
data.add(new Item(150, "Sample Food6"));
data.add(new Item(160, "Sample Food7"));
data.add(new Item(170, "Sample Food8"));
data.add(new Item(180, "Sample Food9"));
data.add(new Item(190, "Sample Food10"));
data.add(new Item(200, "Sample Food11"));
data.add(new Item(210, "Sample Food12"));
adapter = new ItemListAdapter(this, data);
setListAdapter(adapter);
В случае ItemListAdapter Используйте это
public class ItemListAdapter extends ArrayAdapter<Item>
{
private LayoutInflater li;
public ItemListAdapter(Context context, List<Item> items)
{
super(context, 0, items);
li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
final Item item = getItem(position);
View v = convertView;
if (v == null)
{
v = li.inflate(R.layout.fooditem, null);
}
final TextView idView = (TextView) v.findViewById(R.id.itemId);
if (idView != null)
{
idView.setText("" + item.getId());
}
final TextView captionView = (TextView) v.findViewById(R.id.itemCaption);
if (captionView != null)
{
captionView.setText(item.getCaption());
}
return v;
}
@Override
public long getItemId(int position)
{
return getItem(position).getId();
}
@Override
public boolean hasStableIds()
{
return true;
}
}