我想创造这样的。
我的代码是..
void fillCountryTable() {
TableRow row;
TextView tv_lession, tv_price, tv_line;
CheckBox chkbox;
int dip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) 1, getResources().getDisplayMetrics());
for (int current = 0; current < lession.size(); current++) {
row = new TableRow(this);
TableRow.LayoutParams llp = new TableRow.LayoutParams(
);
llp.setMargins(2, 2, 2, 2);// 2px right-margin
// New Cell
LinearLayout cell = new LinearLayout(this);
cell.setBackgroundColor(Color.BLUE);
cell.setLayoutParams(llp);// 2px border on the right for the cell
tv_lession = new TextView(this);
tv_lession.setTextColor(getResources().getColor(color.darker_gray));
tv_price = new TextView(this);
tv_price.setTextColor(getResources().getColor(color.darker_gray));
chkbox = new CheckBox(this);
chkbox.setId(current);
tv_lession.setText(lession.get(current));
tv_price.setText(price.get(current));
tv_lession.setTypeface(null, 1);
tv_price.setTypeface(null, 1);
tv_lession.setTextSize(15);
tv_price.setTextSize(15);
tv_lession.setWidth(50 * dip);
tv_price.setWidth(150 * dip);
chkbox.setWidth(50 * dip);
tv_lession.setPadding(20 * dip, 0, 0, 0);
cell.addView(tv_lession);
cell.addView(tv_price);
cell.addView(chkbox);
// row.setBackgroundColor(color.black);
row.addView(cell);
((TableLayout) findViewById(R.id.course_outline_table)).addView(
row, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
chkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
subTotal += Integer.parseInt(price.get(buttonView
.getId()));
total = subTotal + tax;
} else {
subTotal -= Integer.parseInt(price.get(buttonView
.getId()));
total = subTotal + tax;
}
((TextView) findViewById(R.id.tv_subTotal))
.setText(subTotal + "");
((TextView) findViewById(R.id.tv_total))
.setText(total + "");
}
});
}
}