This explains how to do it when you know the names for the items at compile time, but what if I want them defined at runt开发者_开发技巧ime... i.e. Today, Tomorrow, (Day and Date after Tomorrow), etc...
The items variable has to be declared as final.
No, it doesn't.
Doesn't final mean that I can't change the value?
For that specific example, it is declared final because it is shown as being just a local variable, and the value is also needed inside the anonymous DialogInterface.OnClickListener inner class.
However:
Just because something is declared
finaldoes not mean it has to be a literal. For example, thefinalkeyword is used on parameters to methods sometimes, and those clearly are not statically created. To quote Wikipedia, "A final variable can only be initialized once, either via an initializer or an assignment statement."There are other places you can put your array other than a local variable that will not require the
finalkeyword, if you do not wish to usefinal. One likely candidate would be a data member of your activity.
加载中,请稍侯......
精彩评论