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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:09:25+00:00 2026-05-31T20:09:25+00:00

I have a lot of button inside my application and for every button i

  • 0

I have a lot of button inside my application and for every button i need to create onClickListener, this will incerase line of code’s.

So i create a class for onClickListener below:

    import android.app.Activity;
    import android.content.Intent;
    import android.view.View;

    public class OnClickListener implements android.view.View.OnClickListener{

        Activity current;
        Class<?> goTo;

        public OnClickListener(Activity arg0, Class arg1){
            this.current = arg0;
            this.goTo = arg1;
        }

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(current, goTo);
        }

}

and now i want to go to next activity when button click’s but when i put this line startActivity(intent); compiler shows error The method startActivity(Intent) is undefined for the type OnClickListener

I dont know where i am going wrong and what i am missing. Please help me to solve this problem

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

    You can do in another way too, let your class implement the OnClickListener interface and then implement onClick(...) method, an in that method, switch on view’s id like this:

       @Override
       public void onClick(View v) {
           switch(v.getId()){
               case R.id.btn1:
                   ...
               case R.id.btn2:
                   ...
           }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a lot of button inside a UIScrollView and i am trying to
I have a main div and inside of this, there are a lot of
I have a button click event and inside I do a lot of work.
I have a lot of buttons and by clicking on different button, different image
I have a UITextView that has a lot of content. I have a button
We have lot of object with this kind of design : Interface and several
I have a lot of classes in the App_Code directory could this be a
Hello i have the this problem, i need your help to figure out what
We have a swing application which displays a lot of rectangles. We use Rectangle2D.double
I have a widget and inside it are 32 buttons. I need to connect

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.