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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:43:34+00:00 2026-05-25T19:43:34+00:00

I am kinda new to Android and it would improve my application a lof

  • 0

I am kinda new to Android and it would improve my application a lof if I coul keep several OnClickListenres in one class. What I am thiking of is something like this :

Public class OnClickListeners {

public Button.OnClickListener open;
public Button.OnClickListener doSomethingElse;
public Button.OnClickListener etc;

    public OnClickListeners() {
        open = new Button.OnClickListener()
        {
                public void onClick(View view)
                {
                    DetailList.SetId(view.getId());
                    Intent intent = new Intent(view.getContext(), DetailList.class);
                    startActivityForResult(intent, 100);
                }
        };
    }
}

So I can then reference it in other class B like this

button1.setOnClickListener(OnClickListeners.open);

Any though how to do it?
Android SDK seems to be against me as I can figure it out now for about 2 days now…

Thanks for any advices and help

  • 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-25T19:43:35+00:00Added an answer on May 25, 2026 at 7:43 pm

    There is a sleek way to consolidate all your anonymous classes into one and switch on the view. This works best if you know ahead of time which buttons will be using the clicklistener :

    public class AndroidTestClickListenerActivity extends Activity {
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Button button1 = (Button) findViewById(R.id.button1);
            button1.setOnClickListener(new MyClickListener());
    
            Button button2 = (Button) findViewById(R.id.button2);
            button2.setOnClickListener(new MyClickListener());
    
            Button button3 = (Button) findViewById(R.id.button3);
            button3.setOnClickListener(new MyClickListener());
        }
    
    
    }
    
    class MyClickListener implements View.OnClickListener {
        @Override
        public void onClick(View arg0) {
            switch (arg0.getId()) {
                case R.id.button1:
                    // do soemthign for button1
                    break;
                case R.id.button2:
                    // do something for button2
                    break;
                case R.id.button3:
                    // do something for button3
                    break;
                default:
                    // do something for any other button
    
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new android developer and I am currently making an application to
I am developping an Android application that uses a Facebook component. It would be
I'm new in the android world and I would like to make an android
It's a very common situation, but I'm kinda new using ORM especially in Android,
I'm kinda new to using Rails, and an app I am working on is
I'm kinda new to Java, so haven't yet fully grasped the concept of multithreading.I
I'm kinda new to Flex. I have trying to send Hash from Ruby on
I am kinda new to this Regex thing. When analyzing some code I frequently
I am kinda new to database designing so i ask for some advices or
So, I am kinda new to ASP.net development still, and I already don't like

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.