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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:31:26+00:00 2026-06-05T03:31:26+00:00

From the android development perspective , while you are programming which way do you

  • 0

From the android development perspective, while you are programming which way do you prefer to implement for listener? Or which way do you think is the best for readable code? I gave two example about these things but think more complex classes such as which has more than one Listener:)

First example which is an Anonymous Class:

public class SenderReceiverActivity extends Activity {

Button cancelButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sending);
    cancelButton = (Button) findViewById(R.id.button1);
    cancelButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

        }
    });
}}

Second example which is implementing interface :

public class SenderReceiverActivity extends Activity implements OnClickListener {

Button cancelButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sending);
    cancelButton = (Button) findViewById(R.id.button1);
    cancelButton.setOnClickListener(this);
}

public void onClick(View v) {

}
}
  • 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-05T03:31:28+00:00Added an answer on June 5, 2026 at 3:31 am

    I think 2nd approch is good as

    1- you can handle multiple Views click at one place…

    2- it make code shorter and easy to read..

    3- it is easy in maintenance.

    4- if you are using the Base Activity like concept in your project then it is also useful.

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

Sidebar

Related Questions

Which XMPP library would be the best choice nowadays for Android development? I've been
In Android development, I am loading a drawable from a url with this code:
Is there any quick way to copy eclipse and android development environment from one
From what I've seen, Android development requires the traditional Java style importing of each
i am beginner in Android app development i am working on a app which
I'm just starting with Android development and I'm coming from JavaScript/HTML world so I'm
I am starting Android development. Which of the many Eclipse downloads do I need
I am new to android development. Currently i am working on an application which
Is there any way to share the keystore in a android development team? The
I'm starting android development from just three days, I have downloaded the SDK and

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.