reset password
Author Message
Rinchan7
Posts: 56
Posted 04:16 Oct 15, 2014 |

Hi,

So I was able to get the drop down list to show an object's type using if-else, but I think that this way (while it gets the job done) is a bit inefficient, especially if later on they want to add more types to the drop down list (so that the if-else approach may become troublesome). Does anybody have any ideas on how to do that better?

cysun
Posts: 2935
Posted 08:47 Oct 15, 2014 |

I'd imagine the code would look something like this:

for( String type : types )
if( item.getType().equals(type) )
// display <option> with "selected" attribute
...
else
// display <option> without "selected"
...

So no matter how many types are there, the code doesn't change.

Rinchan7
Posts: 56
Posted 14:42 Oct 16, 2014 |

Got it, I'm planning to implement this to the hw 2 version, thanks!