我通过这样的循环创建一个列表Item
:
private void addItemToList(ItemRepository lst)
{
//Add item to list
for(Item itm:lst.getItems())
{
addItem(itm);
}
}
private void addItem(Item itm)
{
View item = UtilMPos.getViewFromInflater(R.layout.item,Payment_ListItem.this);
TextView lblItemName = (TextView)item.findViewById(R.id.inv_lblitemname);
TextView lblItemDes = (TextView)item.findViewById(R.id.inv_lblitemdesc);
TextView lblPrice = (TextView)item.findViewById(R.id.inv_lblValueItem);
//Set value for text view
lblItemName.setText(itm.getItemName());
lblItemDes.setText(itm.getItemDes());
lblPrice.setText(Double.toString(itm.getPrice()));
//----process component item in here
llstItem.addView(item);
}
然后显示(我使用线性布局来显示列表项):
------------------------------------------------------
item_name 1 Price
item_descripton
------------------------------------------------------
item_name 2 Price
item_descripton
------------------------------------------------------
item_name 3 Price
item_descripton
------------------------------------------------------
单击一行时,将选择该行(粗体行或类似的内容),我可以获得该行的所有数据,例如:单击行 item_name 1 ,我得到所有数据行 1。