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 6833873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:02:13+00:00 2026-05-26T23:02:13+00:00

I might be on the wrong track here, and should be thinking events/publish-subscriber, if

  • 0

I might be on the wrong track here, and should be thinking events/publish-subscriber, if so, please enlighten me.

I have an android project running, where I have a layout which acts as an on-screen menu. Implemented in several activities/”parent-views” with the use of ‘< include>’. Working nicely.

Now, some of the functionality is general and global. Like I have an “add”-button, which does something, that it should always do. Then I’d like the possibility to customize what it does in addition to this, based on the activity where the action originated.

I have seperated menulogic in a simple java class, with the constructor taking an activity as a parameter. From here, I can attach clicklisteners to the buttons in the menu fine, and do stuff on click.

What I’d like is something like:

private void addBtn(String text, String path) {
        LinearLayout ll = (LinearLayout) parentActivity.findViewById(R.id.dynamicButtonLayout);
        Button newButton = new Button(parentActivity);
        newButton.setText(text);
        newButton.setTag(path);
        newButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    //Do Stuff.
                    fireDoneHandlingButtonClick();
                } catch (Exception e) {
                }
            }
        });
    }

And then have a way of handling this method in the parent activity. Should I be thinking of events, or should I be thinking of a way to add a method as an argument to the addBtn method from the activity, which can be fired from inside the click-listener?

  • 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-26T23:02:13+00:00Added an answer on May 26, 2026 at 11:02 pm

    Look at How To Implement Your Own Listener in Android or Fire and Forget Messages (events) in Android

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

Sidebar

Related Questions

I think I might be on the wrong track here so I'm posting this
I'm new to linq and linq to entities so I might have gone wrong
I might be asking the wrong question here, so I apologize if the answer
I might just be using the wrong keywords on Google, but what I have
The major difference between a thing that might go wrong and a thing that
Scenario Ignoring that fact that some of the settings might be wrong and inconsistent
Can anyone spot where I might be going wrong with the following code? <?php
I can't see what I'm doing wrong. I think it might be one of
I'm new to Java Web Services, so I might be doing things wrong. I'm
I have a string that should contain a list of items in the form

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.