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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:47:52+00:00 2026-05-26T20:47:52+00:00

I would like to know if it is possible to create a listener to

  • 0

I would like to know if it is possible to create a listener to a listener. For example if I have a listener for a button, can I create a listener to that listener such that once the button is pressed the listener of the button listener would be notified.

My other concern is if I have a function call which has some listeners inside it would these listeners be destroyed on the return of the function call. For example can I have a function that I call in the beginning of the program that has listeners to listeners from my main program?

  • 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-26T20:47:52+00:00Added an answer on May 26, 2026 at 8:47 pm

    Of course you can. Listeners, or the “Observer Pattern”, are pretty straightforward. All the observer pattern really does is use interfaces to create a “contract” that lets everyone know that a certain class implements a certain method so that you can be confident that you can call it on that object.

    So for example, you can create two interfaces like this:

    public interface OnClickListener {
       public void onClick();
    }
    
    public interface SomeOtherListener {
       public void onFoo();
    }
    

    The code that wishes to “trigger” these methods, must have a reference to those listeners. Typically this is done by exposing some public method to “set the listener(s)”. So in some class, you’d have public void setOnClickListener() { this.onClickListener = listener; } The class that implements the listener can now call setListener(this). Note that “this” works here because interfaces in Java get you that kind of polymorphism. You can cast a class into any of its superclasses or interfaces that it implements. So in the class that wants to call “onClick” for example, all it cares about is that the class that contains the “onClick” IS an “onClickListener”. That’s all that class cares about. Now, as long as the class in which you implement the “onClick” has a reference to the SomeOtherListener (by previously being registered), then the onClick can call someOtherListener.onFoo();

    So, in short, (although it might be a poor design in some cases) you technically can have as many interrelated listeners as you want provided you set it up so that the relevant objects/classes have the references to those listeners that they need.

    Sorry if this was a bit confusing. Also, its hard to provide a more detailed explanation without more details about what exactly you’d like to do.

    EDIT

    To the best of my knowledge, it is not possible to set up some “catchall” to log every GUI event in an Android app. Since interface methods are declared as empty methods that must be implemented, you’d have to specify, in your implementation, the precise logging that you’d like and go from there. You can certainly hack up the Android source to log something every time setOnClickListener is called, for example, but I can’t imagine that being super useful. Also, implicit in this is that you need to do this for every type of listener that’s available. Only listeners that you implement will be available for any sort of logging. If you don’t implement onTouch, for example, then there’s no logging to show for it…

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

Sidebar

Related Questions

i would like to know if this is possible: create a shared git repository
I would like to know if it is possible to create something like Picture
hello i would like to know how would it be possible to create a
I want to know how to create yahoo mail like button (for example their:
I would like to know if it is possible to have a trigger when
I would like know if it is possible to create embedding of audio message
I would like to know if it possible to create a virtual directory directly
I would like to know if it possible to create a virtual directory in
I would like to know if it is possible to create a Flex application
I would like to know if it's possible to create an infinite input select

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.