I give.
I’m trying to extend the TableLayout class ( simply so I can override the onMeasure ) and I’m inflating a TableLayout that’s defined in XML.
The TableLayout shows up (I can see it, due to its custom background) but the TableRows don’t.
Even in the XML “Graphical Layout” of eclipse, if I force the TableLayout to be my custom extended class (com.example.MainApplication.TableLayout_Schedrunning) the nested TableRows aren’t there.
However, if I change the XML to just be TableLayout, the TableRows magically appear.
<?xml version="1.0" encoding="utf-8"?>
<!-- this doesn't work-->
<com.example.MainApplication.Tablelayout_Schedrunning xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frmlay_schedule"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:padding="2dp"
android:background="@drawable/schedrunning_background" >
<TableRow
android:id="@+id/tblrow_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
>
<TextView
android:id="@+id/txtSchedRunningHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Schedule Running"
android:textColor="@android:color/white"
android:textSize="13dp"/>
<TextView
android:id="@+id/txtCurrScheduleRunning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="11dp"/>
</TableRow>
</com.example.MainApplication.Tablelayout_Schedrunning>
So again, to reiterate — if I change the above custom class to the simple <TableLayout>, the nested TextViews in the TableRow show up. If I don’t, they don’t.
What simple thing am I missing??
Oh, and the TableLayout is a pretty standard extension:
public class Tablelayout_Schedrunning extends TableLayout {
public Tablelayout_Schedrunning(Context context) {
super(context);
Log.w("tablelayout","simple context");
// TODO Auto-generated constructor stub
}
public Tablelayout_Schedrunning(Context context, AttributeSet attrs) {
super(context, attrs);
Log.w("tablelayout","advanced, context and attrs");
// TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
Log.w("tablelayout","parentWidth is " + parentWidth);
Log.w("tablelayout","parentHeight is " + parentHeight);
//super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(parentWidth, (int) (parentHeight * .4));
}
I think you should add
super.onMeasureandsetLayoutParamsto your extention of aView