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

  • Home
  • SEARCH
  • 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 6231789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:59:44+00:00 2026-05-24T09:59:44+00:00

sorry if this question is stupid, but I can’t wrap my head around Java

  • 0

sorry if this question is stupid, but I can’t wrap my head around Java syntax..I learnt C/C++
I know View is a class which is good..but I don’t understand if View.OnClickListener() is a method.
I doubt it unless it returns an object?
I think View is a class which has a static OnClickListener member object..again that doesn’t make sense to me..
Can some explain what is happening with this line of code?

button1 = (Button) findByView(R.id.button1)  ;
    button1.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {

        }
    }

So what is happening with this code?

Button1 is a reference to the button1 object in the xml file.

button1 object has a member object setOnClickListener which I from its name I assume initializes an event to the button or something. But it receives View.OnClicListener() object.

I am confused by that..onClick receives a View object so onClickListener is not an object returns a View object?? I don’t get it at all.

Can someone explain what happens in that line View.onClickListener() is it another way of saying new 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-24T09:59:45+00:00Added an answer on May 24, 2026 at 9:59 am

    View.OnClickListener is an interface, you don’t call it, but creates a new instance of it (new View.OnClickListener() is a call to the constructor)

    The instance you create is of anonymous class that implements View.OnClickListener, in the brackets right under new View.OnClickListener()

    Any class that implements View.OnClickListener must implement the methods declared in it (e.g. onClick)

    setOnClickListener just saves the reference to the View.OnClickListener instance you supplied, and when someone clicks the button, the onClick method of the listener you set is getting called.

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

Sidebar

Related Questions

Sorry if this seems like a stupid question but can't find any info on
Sorry if this is a stupid question, but I can't get this to work.
I'm sorry if the question looks stupid,but It seems I can't use my head
Sorry if this question sounds stupid, but I only know HTML/CSS and so I'm
I'm trying to learn Java so sorry if this is a stupid question, but
Sorry if this sounds like a really stupid question, but I need to make
Sorry if this question is very easy, but I can't find the answer anywhere.
sorry for this question, but i dont know where to search for it, or
Firstly I asked sorry if this is a stupid question. but I have a
I'm really sorry. This must seem like an incredibly stupid question, but unless I

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.