I have class which extends LinearLayout
in constructor I call
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout view = (LinearLayout)inflater.inflate(R.layout.titlebar, this, true);
I can access Views in this view but it is not drawn. I think the reason is that mParent of this view is still null. But why? the Partent should be this (the class which extends LinearLayout)
here the xml:
<RelativeLayout android:id="@+id/header"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="35px"
android:layout_width="fill_parent"
android:background="@drawable/titlebar_bg">
<TextView android:layout_width="wrap_content"
android:textColor="#000000"
android:text="test"
android:id="@+id/title"
android:layout_alignParentTop="true"
android:layout_marginLeft="10pt"
android:layout_height="wrap_content"
android:textSize="10pt"
android:layout_marginTop="3dip"></TextView>
<TextView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="10:09 AM"
android:id="@+id/time"
android:textColor="#000000"
android:layout_alignParentRight="true"
android:layout_marginRight="5px"
android:layout_marginTop="3px"
android:textSize="10pt"></TextView></RelativeLayout>
SOLUTION
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_width="wrap_content"
android:textColor="#000000"
android:text="test"
android:id="@+id/title"
android:layout_alignParentTop="true"
android:layout_marginLeft="10pt"
android:layout_height="wrap_content"
android:textSize="10pt"
android:layout_marginTop="3dip"></TextView>
<TextView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="10:09 AM"
android:id="@+id/time"
android:textColor="#000000"
android:layout_alignParentRight="true"
android:layout_marginRight="5px"
android:layout_marginTop="3px"
android:textSize="10pt"></TextView>
using the merge tag and use the xml tags.
<package.Titlebar
android:id="@+id/testtitlebar"
android:layout_height="35px"
android:layout_width="fill_parent"
android:background="@drawable/titlebar_bg"></package.Titlebar>
this is how it looks in the class:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.titlebar, this);
no onLayout function!!! One of my faults