0

I have this Layout common_header.xml which has some buttons.I want to include it in every activity and perform OnClickListener from only one activity.I dont want to use BaseActivity for above operations and extend from it because i have to extend my activities from other activities such as FragmentActivity.I want code reuse in my project. I have tried to include this common_header.xml in my other layout but it desnot work for me,i dont know the reason.followig is my common_header.xml file.

<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_title"
        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>
Dharma
  • 2,425
  • 3
  • 26
  • 40
  • It's pretty unclear what your actual error is here... – Nathaniel D. Waggoner Jan 29 '14 at 04:15
  • You can make your `BaseActivity` to be `FragmentActivity` without any side effects. Then extend the others from `BaseActivity`. Did I miss something? – Andrew T. Jan 29 '14 at 04:18
  • @AndrewT. somewhere i extend from FragmentActivity and somewhere from other such as Fragment and i think i will have different BaseActivities for them also. so it will again be hard to reuse code.isn't it sir? – Dharma Jan 29 '14 at 04:24
  • @NathanielWaggoner:will u have a look to my next question sir, http://stackoverflow.com/questions/21379002/same-layout-and-same-onclicklisteners-for-multiple-activities – Dharma Jan 29 '14 at 04:26

2 Answers2

0

You can use which will include the header file in layouts...for reference check the links below

How to add header and Footer to each activity in android

Android / layout: how to create a header-content layout

http://www.javacodegeeks.com/2013/10/android-header-and-footer-layout-example.html

Community
  • 1
  • 1
arun
  • 227
  • 1
  • 5
  • 16
0

include common_header in xml(s)

findviewbyId for the imagesbuttons in the activity , set listeners, no reason why it should not work

It'l help if you paste the code from an activity where it does not work, with the xml for the same

Pararth
  • 8,114
  • 4
  • 34
  • 51
  • :please have a look to this question:http://stackoverflow.com/questions/21379002/same-layout-and-same-onclicklisteners-for-multiple-activities – Dharma Jan 29 '14 at 04:39