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

  • Home
  • SEARCH
  • 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 7029229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:30:40+00:00 2026-05-28T00:30:40+00:00

I have a Header at the top of 3 lists, which contains simple Create

  • 0

I have a “Header” at the top of 3 lists, which contains simple Create Read Update & Delete buttons for editing the list.

How should I go about subclassing the Header so I can overwrite the listener in TaskHeader, ProjectHeader, ClientsHeader (Subclasses)

seeing as the layout, button creation, assignment etc.. can all be done in the same implementaion and just assigning the listener can be delegated to the specific sub-class.

Updated with suggested solution

Interface

import android.view.View.OnClickListener;

public interface AttachClickListeners {

void attachCreateListener(OnClickListener l);
void attachReadListener(OnClickListener l);
void attachUpdateListener(OnClickListener l);
void attachDeleteListener(OnClickListener l);

}

Header

public class Header extends LinearLayout implements AttachClickListeners {
/* removed for shortness */
public void attachCreateListener(OnClickListener listener) {
    insertBtn.setOnClickListener(listener);
}

public void attachReadListener(OnClickListener listener) {
    selectBtn.setOnClickListener(listener);
}

public void attachUpdateListener(OnClickListener listener) {
    updateBtn.setOnClickListener(listener);
}

public void attachDeleteListener(OnClickListener listener) {
    deleteBtn.setOnClickListener(listener);
}

then each time I create a header I just pass a different listener object as suggested by @elijah

  • 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-05-28T00:30:41+00:00Added an answer on May 28, 2026 at 12:30 am

    if the UI and behavior can be shared, you shouldn’t have to subclass the header.

    Instead, create interface definitions for listener classes for the events you want to respond to. For instance, if you want to have different responses to the Create button, define a onCreateClickedListener interface, and then create particular instances of that interface for every view the shared header object exists in. You have to register the listener; something like:

    createClickedListener = new onCreateClickedListener() {
      @Override
      public void onClick() { ... }
    };
    
    header.setOnCreateClickedListener(createClickedListener);
    

    This tutorial covers the topic in depth.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a navbar at the top of my website which contains multiple
I have a simple UITableView with two sections. Each section has a header which
I would like to have a header on top of a ListView , but
i have this header at the top: http://yoursdproperty.com/ how do i move the swf
What I am trying to is have a header image centered on the top
I have a view which is composed of top, left and bottom headers and
How to align the buttons bottom of the screen.In the layout i have header
I have a header area which is divided up into block areas for images,
I have a long list of elements which I would like to scroll while
I'm developing a List of four items. Each item needs to have a top

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.