Android Localization problem: Not all items in the layout update properly when switching locales

前端 未结 4 863
北海茫月
北海茫月 2021-02-07 18:27

Here\'s the problem: When I have an activity running in the background, and I switch locales, and I switch back to the application, everything updates... EXCEPT checkboxes and r

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 19:19

    That is a fascinating bug. I can reproduce it on my Nexus One.

    It seems to be in the default implementation of onSaveInstanceState(). If you override that to be a no-op (do not chain to the superclass), the problem goes away.

    The default onSaveInstanceState() is supposed to handle stuff like the checkbox state, but they must have botched that and are saving the text, too.

    So, you have a couple of workarounds:

    1. Override onSaveInstanceState() and do not chain to the superclass. This, however, eliminates any automatic state-saving you would ordinarily get.
    2. In onRestoreInstanceState() (...I think...), after chaining to the superclass, call setText() on your affected widgets with the proper string resource, to reset it back to the right value.

    I will try to follow up on this more tomorrow when I get a chance. I want to check the source code and probably file this as an issue.

提交回复
热议问题