Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8283079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:36:28+00:00 2026-06-08T10:36:28+00:00

I’ve got an android app, with a super-class that contains a layout that should

  • 0

I’ve got an android app, with a super-class that contains a layout that should be static for each activity, the illustration beneath shows this in a better way rather than my description

enter image description here

This “header” contains a tabBar which contains a ImageButton. I want this header to be static for all the activities in my app. What I tried to do, is to extend my other classes from this superclass. Code for the super class is beneath

public class MySuperClass extends Activity {
 MyHorizontalScrollView scrollView;
 View menu;
 View app;
 ImageButton btnSlide;
 boolean menuOut = false;
 Handler handler = new Handler();
 int btnWidth;

 Button testClass; 

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LayoutInflater inflater = LayoutInflater.from(this);
    scrollView = (MyHorizontalScrollView) inflater.inflate(R.layout.horz_scroll_with_list_menu, null);
    setContentView(scrollView);

    menu = inflater.inflate(R.layout.horz_scroll_menu, null);

    app = inflater.inflate(R.layout.horz_scroll_app, null);
    ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar);

    ListView listView = (ListView) app.findViewById(R.id.list);

    listView = (ListView) menu.findViewById(R.id.list);

    ArrayList<MenuItem> menuItems = getMenuItems();
    listView.setAdapter(new MenuCustomAdapter(this, menuItems)); 

    btnSlide = (ImageButton) tabBar.findViewById(R.id.BtnSlide);
    btnSlide.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch(event.getAction()) {

            case MotionEvent.ACTION_DOWN:
                btnSlide.setImageResource(R.drawable.lincolor);
                break;
            case MotionEvent.ACTION_UP:
                btnSlide.setImageResource(R.drawable.lin);
                break;
            }

            return false;
        }


    });
    btnSlide.setOnClickListener(new ClickListenerForScrolling(scrollView, menu));

    testClass = (Button) app.findViewById(R.id.button1);

    testClass.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            Intent intent = new Intent(MySuperClass.this, TestClass.class);
            startActivity(intent); 
        }


    });

    final View[] children = new View[] { menu, app };

    // Scroll to app (view[1]) when layout finished.
    int scrollToViewIdx = 1;
    scrollView.initViews(children, scrollToViewIdx, new SizeCallbackForMenu(btnSlide));
}

public ArrayList<MenuItem> getMenuItems() {
    ArrayList<MenuItem> items = new ArrayList<MenuItem>();


    MenuItem m1 = new MenuItem(R.drawable.scroll, "Show history"); 
    items.add(m1);
    MenuItem m2 = new MenuItem(R.drawable.right, "Right"); 
    items.add(m2);

    return items;
}


/**
 * Helper for examples with a HSV that should be scrolled by a menu View's width.
 */
static class ClickListenerForScrolling implements OnClickListener {
    HorizontalScrollView scrollView;
    View menu;
    ImageButton button;
    int pressed;
    int timeout;
    /**
     * Menu must NOT be out/shown to start with.
     */
    boolean menuOut = false;

    public ClickListenerForScrolling(HorizontalScrollView scrollView, View menu) {
        super();
        this.scrollView = scrollView;
        this.menu = menu; 
    }



    @Override
    public void onClick(View v) {
        Context context = menu.getContext();

        int menuWidth = menu.getMeasuredWidth();

        // Ensure menu is visible
        menu.setVisibility(View.VISIBLE);

        if (!menuOut) {
            // Scroll to 0 to reveal menu
            int left = 0;
            scrollView.smoothScrollTo(left, 0);
        } else {
            // Scroll to menuWidth so menu isn't on screen.
            int left = menuWidth;
            scrollView.smoothScrollTo(left, 0);
        }
        menuOut = !menuOut;
    }


}

/**
 * Helper that remembers the width of the 'slide' button, so that the 'slide' button remains in view, even when the menu is
 * showing.
 */
static class SizeCallbackForMenu implements SizeCallback {
    int btnWidth;
    View btnSlide;

    public SizeCallbackForMenu(View btnSlide) {
        super();
        this.btnSlide = btnSlide;
    }

    @Override
    public void onGlobalLayout() {
        btnWidth = btnSlide.getMeasuredWidth();
        System.out.println("btnWidth=" + btnWidth);
    }

    @Override
    public void getViewSize(int idx, int w, int h, int[] dims) {
        dims[0] = w;
        dims[1] = h;
        final int menuIdx = 0;
        if (idx == menuIdx) {
            dims[0] = w - btnWidth;
        }
    }
}

}

And a test class, which extends this superclass.

public class TestClass extends MySuperClass {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);

}

}

Again how can I make the tabBar static for each activity?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:36:30+00:00Added an answer on June 8, 2026 at 10:36 am

    There is no way to achieve this in an Activity-scope. The layout are independent from your Acitvity (well, until you bind them).

    The solution to your problem, may be in using a common header layout, kept in a xml file under your layout folder, something like this:

    header.xml:

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/red"
        ... />
    

    And include them in your layouts, using the include tag:

    my_activity_layout.xml:

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        ....
        .... >
    
        <include layout="@layout/header.xml" android:id="@+id/header" />
    
        <!-- Countinue your layout .... -->
    
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.