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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:05:24+00:00 2026-05-28T03:05:24+00:00

I am a .NET mobile developer and since i started working with android, i

  • 0

I am a .NET mobile developer and since i started working with android, i noticed that the only way i can store my event handlers of the views is through the activity file or by creating a class to hold all these event listeners. Can someone suggest best way that i can do to have the least clutter and store all the event handlers accordingly?

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

    A bit subjective as “clutter” depends on how efficient you are at implementing your event handlers and how complex your app is.

    For instance I’ve seen example code here on SO like…

    button1.setOnClickListener(new View.OnClickListener {...});
    button2.setOnClickListener(new View.OnClickListener {...});
    button3.setOnClickListener(new View.OnClickListener {...});
    

    In each case an anonymous listener for each individual Button often performing a very similar function (start activity 1, start activity 2….). The cleanest way would be to implement View.OnClickListener on the Activity itself and then use…

    button1.setOnClickListener(this);
    

    …(and so on for each Button) then get the resource id of the View passed in to the listener to identify what was clicked and what needs to be done. It amazes me how many people don’t get that.

    As for creating a separate class (or classes) to hold listeners, that gets tricky depending on how many activities you have going on. Maintaining the listeners separately has two downsides.

    Firstly if you don’t go with the model of having an Activity use anonymous listeners or implement the listener directly, that suggests you’ll have a whole load of activities (which may be extended at some point) using your ‘helper’ class listeners. Each time you extend your Activity you need to make sure the separate class is updated to cope with it – potentially an out of sight, out of mind problem where you want something new from an Activity which your ‘generic’ listener doesn’t handle.

    The second potential problem is in the way Android works (depending on your app). An Android Activity is meant to be modular – if it displays photos or images or documents of a particular format then it should be as self-contained as possible. Having a separate class with a multitude of listeners in means that a very simple Activity meant to do a very simple task ends up loading a bloat of a class (or classes) which contains a whole load of listeners which aren’t relevant.

    Stick with simple – optimise the listeners for each Activity and keep them self-contained. If you feel there’s any duplication going on, define your own base classes and extend from there.

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

Sidebar

Related Questions

I'm a C# .NET developer. I want to develop mobile apps that can run
I want to develop a mobile web application using asp.net 3.5 that can be
For a .net developer, what's the learning curve to get into mobile development? How
My requirements: Support .NET Compact Framework 2.0 and Windows Mobile 6.0 devices. Only need
I've included a mobile web form in my asp.net project, I thought that it
I have a .net 3.5 application running on windows mobile professional that uses sql
I am working on a mobile application in .NET. This is a windows mobile
Can we develop mobile applications using .NET? Which mobiles are supported? Are those applications
I'm a .NET/Flex web/windows developer about to make the plunge into mobile development. I
I am creating mobile application in asp.net webform targeting IPhone, Android and blackberry. 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.