El diseño personalizado no se muestra

I am trying to make a reusable header. Here is my XML.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg" >

    <ImageButton 
        android:id="@+id/imagebuttonforheader"
        android:layout_height="50dp"
        android:layout_width="50dp"
        android:layout_alignParentLeft="true"
        android:background="@drawable/back_button"
        />

    <ImageButton 
        android:id="@+id/imagebuttonforheader"
        android:layout_height="50dp"
        android:layout_width="50dp"
        android:layout_alignParentRight="true"
        android:background="@drawable/forward_button"
        />

</RelativeLayout>  

I made a class for it:

public class Header extends RelativeLayout {
    Context context;
    Activity activity;

    public Header(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        LayoutInflater li  = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        li.inflate(R.layout.header, null, false);
    }
}

And then added this layout into my main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <my.testy.view.Header
        android:id="@+id/headerOnMain"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >
    </my.testy.view.Header>

    <TextView
        android:id="@+id/textView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/headerOnMain"
        android:text="@string/hello" />
</RelativeLayout>

But it's not showing up on the application.

¿Qué estoy haciendo mal aquí?

preguntado el 10 de marzo de 12 a las 16:03

1 Respuestas

You have to attached your inflated layout to your custom class:

li.inflate(R.layout.header, this, true);

respondido 10 mar '12, 16:03

Thanks. it worked. I can't believe i forgot this. It has been killing me for hours! - prometheuspk

@Prometheus87 Also I don't see your entire R.layout.header, but have a look at this article(if you didn't do it already) -> desarrollador.android.com/resources/articles/… - usuario

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.