I have created a TableRow layout model which I’m using as a template for a custom View that extends TableRow.
My desire is to inflate the row inside the extended class, AND have that inflated instance BE the extended row.
In pseudo code:
public class MyTableRow extends TableRow{
if(conditionA)
this = (TableRow)inflate(R.layout.myModelRowA);
if(conditionB)
this = (TableRow)inflate(R.layout.myModelRowB);
etc...
}
And then when I’m adding these rows to the table I’d proceed as usual…
myTable.addView(new MyTableRow(this));
So, the issue is that obviously I can’t assign things to this even if logically it makes perfect sense, since in the example above this is a TableRow.
Is there another way to do this? I know it looks stupid, but my current alternative is to house the inflated TableRow as a member of MyTableRow, which works, but is really ugly (and doesn’t feel very OO).
Am I missing something obvious? Or should I just settle for what I have?
Define your Row A and Row B layouts with tag <merge> (see here) instead of <TableRow>:
then inflate one of these layouts in your extended row constructor:
Then in your Table layout use your extended Row instead of TableRow: