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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:42:00+00:00 2026-05-16T07:42:00+00:00

Basically, so far I’ve just got an add and minus button which will change

  • 0

Basically, so far I’ve just got an add and minus button which will change the value of a TextView.

I followed the second example under “Event Listeners” on http://developer.android.com/guide/topics/ui/ui-events.html

The problem is I get 4 errors when I go to compile, I don’t see what I’m doing wrong?

Please can someone point out if there is anything wrong, or show me a simpler way please.

Thank you for your time.

Here’s the errors:

/home/alex/NetBeansProjects/GolfScoreCard/src/com/alex/golfscorecard/MainActivity.java:19: com.alex.golfscorecard.MainActivity is not abstract and does not override abstract method onClick(android.content.DialogInterface,int) in android.content.DialogInterface.OnClickListener
public class MainActivity extends Activity implements OnClickListener{
/home/alex/NetBeansProjects/GolfScoreCard/src/com/alex/golfscorecard/MainActivity.java:49: setOnClickListener(android.view.View.OnClickListener) in android.view.View cannot be applied to (com.alex.golfscorecard.MainActivity)
        buttonMinus.setOnClickListener(this);
/home/alex/NetBeansProjects/GolfScoreCard/src/com/alex/golfscorecard/MainActivity.java:50: setOnClickListener(android.view.View.OnClickListener) in android.view.View cannot be applied to (com.alex.golfscorecard.MainActivity)
        buttonPlus.setOnClickListener(this);
/home/alex/NetBeansProjects/GolfScoreCard/src/com/alex/golfscorecard/MainActivity.java:51: setOnClickListener(android.view.View.OnClickListener) in android.view.View cannot be applied to (com.alex.golfscorecard.MainActivity)
        buttonOK.setOnClickListener(this);

Here is my code:

package com.alex.golfscorecard;

import android.app.Activity;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 *
 * @author alex
 */
public class MainActivity extends Activity implements OnClickListener{
  Button buttonMinus, buttonPlus, buttonOK;
  TextView golfScore;

    // Implement the OnClickListener callback
    // Incomplete!
    public void onClick(View v) {
      switch(v.getId()){
          case R.id.buttonMinus:
          score--;
          break;
          case R.id.buttonPlus:
          score++;
          break;
      }
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        //Set the UI elements and find their view in main.xml
        buttonMinus = (Button) findViewById(R.id.buttonMinus);
        buttonPlus = (Button) findViewById(R.id.buttonPlus);
        buttonOK = (Button) findViewById(R.id.buttonOK);
        golfScore = (TextView) findViewById(R.id.golfScore);

        //Set the UI elements' on click listeners
        buttonMinus.setOnClickListener(this);
        buttonPlus.setOnClickListener(this);
        buttonOK.setOnClickListener(this);

    }

}
  • 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-16T07:42:01+00:00Added an answer on May 16, 2026 at 7:42 am

    You have imported wrong OnClickListener. Change

    import android.content.DialogInterface.OnClickListener;
    

    to

    import android.view.View.OnClickListener;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far I have this case statement working where I basically assign a value
Basically, what I've got going is a timer that counts every half second and
Basically, I have the following so far: class Foo { public override bool Equals(object
That's basically it, as far as I can tell. I can include or require_once
Not sure how to word the question... Basically, so far all my SQL stuff
Basically, I have a UIImageView that will loop through 8 PNGs over 0.5 seconds.
Basically I've made a form in Cakephp 2.1 with a jQuery button that appends
Basically I have 4 images and 4 button. All 4 images are black and
Basically, I'm building a small tracker for experimental purposes. I've gotten quite far, and
I have a javascript lib, basically this is how it is structured so far:

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.