开发者

How can I make an AlertDialog with multiple items whose names are defined at runtime?

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:

  1. Just because something is declared final does not mean it has to be a literal. For example, the final keyword 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."

  2. There are other places you can put your array other than a local variable that will not require the final keyword, if you do not wish to use final. One likely candidate would be a data member of your activity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜