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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:57:44+00:00 2026-06-09T03:57:44+00:00

Is View.OnClickListener() a function or interface? When we try to set a onclicklistener() method

  • 0

Is View.OnClickListener() a function or interface? When we try to set a onclicklistener() method in android, we use new View.OnClickListener() and it bugs me there cuz as far as I know,

  • we don’t need to initialize an object of class containing static method inorder to use those methods. Why we do this?
  • When we use implements inorder to implement an interface, we don’t call the static methods of the interface.

So can some one tell me why do we do:

  • new View.OnClickListener(), for using onclick() method?
  • Why do we use () with View.OnClickListener if it is an interface?

Thanks for your reply..

  • 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-09T03:57:46+00:00Added an answer on June 9, 2026 at 3:57 am

    I’m not sure I understand what you are writing about static methods. View.OnClickListener is an interface: http://developer.android.com/reference/android/view/View.OnClickListener.html

    To set a click listener on a view, you pass an instance implementing the OnClickListerner interface: http://developer.android.com/reference/android/view/View.html#setOnClickListener(android.view.View.OnClickListener)

    The most common way to do this in android is to define an anonymous inner class (http://docs.oracle.com/javase/tutorial/java/javaOO/innerclasses.html) that implements OnClickListener like

    myView.setOnClickListener(new View.OnClickListener() {
        @Override           
        public void onClick(View v) {
            // Handle view click here           
        }
    });
    

    The code above both defines an anonymous inner class and creates an instance of it. It is equivalent to first defining a class implementing View.OnClickListener (if defined in the same class)

    class MyOnClickListener implements View.OnClickListener {
        @Override           
        public void onClick(View v) {
            // Handle view click here           
        }
    }
    

    And later using this

    MyOnClickListener listener = new MyOnClickListener();
    myView.setOnClickListener(listener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code: button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // fileReader(); new xyz().execute(); }//
button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { db.update(); } }); On line
Here is my code: private Button.OnClickListener gotologinpage3 = new Button.OnClickListener() { public void onClick(View
I am trying use the onClick() function in an activity for an android app.
package com.duncan.hello.world; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;
This is my onCreate function. Since there is lot of code inside onclickListener for
I've built a simple customized view and registered onClickListener() in a constructor. To start
The View.remove() function in backbone js removes the container element of the view itself
So hey guys I want to return an integer to outside my OnClickListener function:
I am developing an android application with one basic function, to allow the user

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.