我喜欢上课
public class Items {
public int icon;
public String label;
public String price;
public String offer;
public Items(){
super();
}
public Items(int icon, String label,String price,String offer) {
super();
this.icon = icon;
this.label = label;
this.price = price;
this.offer = offer;
}
}
我为该类创建了对象,如
Items items_data[] = new Items[]
{
new Items(R.drawable.ic_launcher, "Samsung","400","Hot Item"),
new Items(R.drawable.ic_launcher, "Samsung1","4001","Hot Item1"),
};
现在我需要在表格行中显示上面的值,如第一行我必须显示第一个位置,依此类推。 请帮忙。
答案 0 :(得分:1)
你可以试试这个:
Items items_data[] = new Items[] {
new Items(R.drawable.ic_launcher, "Samsung", "400", "Hot Item"),
new Items(R.drawable.ic_launcher, "Samsung1", "4001", "Hot Item1"),
};
TableLayout tl = new TableLayout(this);
for (Items items : items_data) {
TableRow tr = new TableRow(this);
ImageView iv = new ImageView(this);
iv.setBackgroundResource(items.icon);
tr.addView(iv);
TextView label = new TextView(this);
label.setText(items.label);
tr.addView(label);
TextView price = new TextView(this);
price.setText(items.price);
tr.addView(price);
TextView offer = new TextView(this);
offer.setText(items.offer);
tr.addView(offer);
tl.addView(tr);
}
your_layout.add(tl);