I have a header that i have to include in multiple activities and i want to handle the OnClickListener for the Buttons from same activity. i followed this question Button Onclick Listener in included layouts
but in my case it doesnot work. i have common_header.xml as:
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/layout_top_bar"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:clickable="true"
android:background="@color/titlebarBackground"
>
<ImageButton
android:id="@+id/btn_menu"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="menu"
android:background="@drawable/borderless_button_unselected"
android:src="@drawable/menu"
/>
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/btn_account"
android:textColor="@color/titlebarForeground"
android:textSize="16sp"
android:text="@string/signin"
android:background="@drawable/transparent_signin_selector"
/>
<ImageButton
android:id="@+id/btn_account"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:contentDescription="menu"
android:background="@drawable/borderless_button_unselected"
android:src="@drawable/account"
/>
</RelativeLayout>
<ListView
android:id="@+id/listview_account"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/menuDivider"
android:dividerHeight="1px"
android:layout_below="@+id/layout_top_bar"
android:visibility="gone"
>
</ListView>
<ListView
android:id="@+id/listview_menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/menuDivider"
android:dividerHeight="1px"
android:layout_below="@+id/layout_top_bar"
android:visibility="gone"
>
</ListView>
</merge>
and in another layout i have used it like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/appBackground" >
<com.example.myApp.MenuView
android:id="@+id/common_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
.../>
<Button
.../>
</RelativeLayout>
my MenuView class is:
public class MenuView extends RelativeLayout {
private LayoutInflater inflater;
public MenuView(Context context, AttributeSet attrs) {
super(context, attrs);
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.common_header, this, true);
}
}
it doesnot show me any error the app runs but the common_header is not merged in my layout.i couldnot figure out where is my mistake.so please help.