a switch statement is made for nested if statements. switch statement is greate if you have a bunch of selections, to make a switch statement perform better you have to look at what user will likely selection the most, and implement that case on the top most case in the switch. Accessing that case will be faster than accessing cases at lower end of the switch statement.
On Wed, Apr 29, 2009 at 6:35 AM, Steve <[email protected]> wrote: > > This would be a good setup if you were planning on adding more menu > items later, such as About or Settings or whatever. > > On Apr 29, 2:22 am, asymmetric <[email protected]> wrote: > > fadden, thanks for your reply. > > > > i'm curious as to why the android devs only used switch statements > > then, if, as you say, an if statement would have been more efficient.. > > hmm.. > > > > anyway, thank you! > > asymmetric > > > > On Apr 28, 10:37 pm, fadden <[email protected]> wrote: > > > > > > > > > On Apr 28, 4:33 am, asymmetric <[email protected]> wrote: > > > > > > by looking at the Notepad examples, i've noticed that the switch > > > > statement is used even when there's only one case handled, as in: > > > [...] > > > > my question is, which is the most efficient statement? are there any > > > > noticeable differences, enough to justify a refactoring? > > > > > For a single element, an "if" statement will be faster and more > > > compact. > > > > > Unless you're calling it thousands of times per second, it's not going > > > to make a difference in performance. It's probably using about 20 > > > more bytes of Dalvik bytecode than the equivalent "if", so unless you > > > have a bunch of them the size won't matter either. > > > > > Having all of the code look roughly the same may make it easier to > > > understand and maintain. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" 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-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

