I want to crate custom TableLayout with rows like this:
TV is for TextView, i.e. I want to add 11 TextViews to the row:
Try programmatically setting all columns to stretch (didn't seem to work in XML for me):
...
flowTable.addContent(data);
flowTable.setStretchAllColumns(true);
Some other quick facts:
Might I also humbly suggest a bit of refactoring:
public class FlowTable extends TableLayout {
private TableRow mCurrentRow;
public FlowTable(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public FlowTable(Context context) {
super(context);
init();
}
private void init() {
mCurrentRow = new TableRow(getContext());
mCurrentRow.addView(createAndFillTextView("0")); // title for first row
setStretchAllColumns(true);
}
public void addContent(List data) {
for (int i = 0; i < data.size(); i++) {
if ((i % 5 == 0) && (i != 0) /** Don't do this on 0! */) {
finishRowAndStartNew(i);
}
mCurrentRow.addView(createAndFillTextView(data.get(i).distance));
mCurrentRow.addView(createAndFillTextView(data.get(i).result));
}
}
private void finishRowAndStartNew(int newRowIndex) {
addView(mCurrentRow);
mCurrentRow = new TableRow(getContext());
mCurrentRow.addView(createAndFillTextView(genRange(newRowIndex+1)));
}
private String genRange(int currIndex){
/********************/
return String.valueOf(currIndex);
}
private TextView createAndFillTextView(String text) {
TextView tv = new TextView(getContext());
tv.setText(text);
return tv;
}
}