0

我有课喜欢

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"),

};

现在我需要在表格行中显示上述值,例如在第一行中我必须显示第一个位置等等..请帮忙。

4

1 回答 1

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);
于 2013-07-18T09:24:48.647 回答