0

I m new to android but familiar with .net.

I want to add 5 menu buttons in header tht will be repeated on every page. So I'm including headertemplet.xml in every page.

But how can I write single button clicks for all these buttons.

How should I proceed?

3 Answers 3

0

Try this as you have created one headertemplet.xml file use include tag to add that xml file where ever you want.

 <include  layout="@layout/Your_XML_File_Name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
2
  • yeah i did it already.and my xml file has five buttons i want to handle clicks of these buttons altogether Oct 26, 2012 at 12:15
  • since you have included the your xml file you can get the id of the respective button or you can use Tab.Read this androidhive.info/2011/08/android-tab-layout-tutorial
    – Akshay
    Oct 26, 2012 at 12:17
0

It might be an overkill, but you could use Fragments to do this.

The idea is a Fragment to handle the layout and clicks of the five buttons (passing the clicks to the Activity to handle it properly if needed), and another fragment to handle the rest of the screen.

As you said, the buttons will be present on all pages, so you only need to change the second fragment using FragmentTransaction.

-1

You cant do with single on click event because onClick Require Context which is seperate for each activity.

BTW you can include it in each of your layout (which might you have done) so Rest of Operation(from finding ID to your last Result) you have to do in each activity

3
  • if i write tht listner in a function then? Oct 26, 2012 at 12:12
  • ohk got it still its not possible then any other alternative? Oct 26, 2012 at 12:13
  • @user1685608 sorry mate but i dont think it is possible.:(:( Oct 26, 2012 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.