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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:37:06+00:00 2026-06-10T15:37:06+00:00

I have MainMenu. There’s 3 different ImageButtons for starting new Activities. Everything work fine,

  • 0

I have MainMenu. There’s 3 different ImageButtons for starting new Activities. Everything work fine, but I wondering is possible another way to code this. I took this from example code with one button, and I think its not look good: setting new OnClickListener() for each button.

public class MainMenu extends Activity implements OnClickListener{

ImageButton firstModule;
ImageButton secondModule;
ImageButton thirdModule;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_menu);

    //init buttons
    firstModule =  (ImageButton) findViewById(R.id.imageButton1);
    secondModule = (ImageButton) findViewById(R.id.imageButton2);
    thirdModule =  (ImageButton) findViewById(R.id.imageButton3);

    firstModule.setOnClickListener(this);
    secondModule.setOnClickListener(this);
    thirdModule.setOnClickListener(this);
}
public void onClick(View v) {

    switch(v.getId()){
    case R.id.imageButton1:
        startActivity(new Intent(MainMenu.this, BasicFunctions.class));
        break;
    case R.id.imageButton2:
        startActivity(new Intent(MainMenu.this, GpsModule.class));
        break;
    case R.id.imageButton3:
        startActivity(new Intent(MainMenu.this, Graphic3D.class));
        break;
    }

}

}

  • 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-10T15:37:08+00:00Added an answer on June 10, 2026 at 3:37 pm

    The more elegant way is to implement View.OnClickListener inside your Activity and then process clicks inside the onClick() method of your Activity. It gives you a View object as an argument, you can retrieve the view’s id using the view.getId() method, then you can use the switch block to implement actions for every Button in your layout. Hope this helps.

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

Sidebar

Related Questions

I have a MainMenu in my app and I would like to have little
I have an app that so far consists of two Activities: The Main Menu
I´m newbie. I have three xib files in my cocoa app: MainMenu.xib the main
On further investigation I have discovered that there is something in my CSS that
I have a TabActivity with 3 tabs. There is an async task that when
Many of menus have always one item same to all. Is there the way
I have a class (TextEditorViewController) within there is a NSTextView (textView) Object. I've connected
I have an NSMenuItem titled Word Wrap in my main menu (MainMenu.xib). Its value
I know that there are already posts about this error around stack overflow, but
I am working on a site. And have some menu. But i have a

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.