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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:12:01+00:00 2026-05-22T21:12:01+00:00

The elseif(v == button2) line gives an error saying that Syntax error on token

  • 0

The elseif(v == button2) line gives an error saying that “Syntax error on token ‘==’, delete this token”. I got the idea of using this from the topic “Variable OnClick listener android” from this website. Can anyone please tell me how to use it?

Here is my code:

    View.OnClickListener yourListener = new View.OnClickListener(){
        public void onClick(View v){
            if( v ==  button1){
                new AlertDialog.Builder(this)
                .setTitle("Paracettamol")
                .setMessage("This medicine is generally used to cure Fever")
                .setNeutralButton("OK", null)
                .show();}
            }
        elseif( v == button2){
            new AlertDialog.Builder(this)

        .setTitle("sertraline")
        .setMessage("This medicine is generally used to cure Head aches")
        .setNeutralButton("OK", null)
        .show();

        }



        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }
        }  ; 
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }
        }

The answer of the asked question mentioned above has the following code:

Button btn1, btn2;
public void onCreate(Bundle b)
{
    // here you do normal things like assigning a
    // content view to the activity, initiate buttons, etc.

    // then you assign the same listener to both buttons
    btn1.setOnClickListener(yourListener);
    btn2.setOnClickListener(yourListener);
}

// declare a OnClickListener that will execute different actions
// depending on the view that was clicked
View.OnClickListener yourListener = new View.OnClickListener(){
    public void  onClick  (View  v){
        if( v == btn1 ){
            // do something 
        }
        elseif( v == btn1 ){
            // do another thing
        }
    }
};
  • 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-22T21:12:01+00:00Added an answer on May 22, 2026 at 9:12 pm

    ah…

    Your code sample is a mess…

    I’ve re-formatted it and correct errors. Now it should work.

    View.OnClickListener yourListener = new View.OnClickListener() {
            public void onClick(View v) {
                if (v == button1) {
                    new AlertDialog.Builder(v.getContext())
                            .setTitle("Paracettamol")
                            .setMessage(
                                    "This medicine is generally used to cure Fever")
                            .setNeutralButton("OK", null).show();
                } else if (v == button2) {
                    new AlertDialog.Builder(v.getContext())
                            .setTitle("sertraline")
                            .setMessage(
                                    "This medicine is generally used to cure Head aches")
                            .setNeutralButton("OK", null).show();
                }
    
            }
        };
    

    Could you be more accurate asking question next time?

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

Sidebar

Related Questions

I can't find whats the wrong with this script. Please help me! {elseif $text[i].text
Ok, so I'm making a program that will read from a text file, convert
I've built this actionPerformed method so that it reads a string I pass to
I know that this question has been asked loads of times, but I have
Not sure whats wrong here the error report says line 9, but when I
This is a javascript homework exercise. The problem is a combination of a syntax
Switch statements are typically faster than equivalent if-else-if statements (as e.g. descibed in this
why won't this work? function login(){ if(window.XMLHttpRequest){ ajax=new XMLHttpRequest(); }else if(window.ActiveXObject){ ajax=new ActiveXObject(Microsoft.XMLHTTP); }
How can I do this cleanly without gotos? loop: if(condition1){ something(); } else if
This script only runs once. I click a button and it changes the menu.

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.