And now the answer you have been dreading --- it depends;)

In earlier versions of Android, we had to worry about the overhead for
each anonymous class. But with the later versions, I don't think this
overhead is significant anymore -- though I have not seen official
confirmation of this from Google.

A more important consideration is the readability of your code: which
do you find more readable? The massive switch statement, or a swarm of
anonymous classes? After all, if it is only 15, the calculations to
choose between the 15 cases just can't take that long. But that code
would likely prove harder to read.

Readability is more important since as Knuth says, premature
optimization is the root of all evil (http://en.wikiquote.org/wiki/
Donald_Knuth).

On Sep 29, 3:55 am, LazyGarfield <[email protected]>
wrote:
> Hi Everyone!
>
> I have got around 15 buttons in my activity.
>
> I just wanted to know that what would be a better approach to
> implement their ClickListeners. Should I write a single ClickListener
> and use Switch case or I should write it individually fr each button?
>
> I got confused between these two because on a couple of blogs, it is
> suggested to write individual ones from the viewpoint of performance
> and efficiency but, considering cumbersome and complexity of overall
> code I feel like going with approach 1 i.e. switch case. Kindly give
> your suggestions about the right approach and the reason why I should
> prefer that.
>
> TIA.
>
> Regards!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to