본문 바로가기

소프트웨어/안드로이드

[Android/Kitkat] 로케일 변경 시 CheckBox 텍스트가 업데이트 되지 않는 현상 해결

 

 

1) onResume에서 텍스트를 업데이트

@Override
protected void onResume() {
    checkBox.setText(R.string.text);
}

 

 

 

 

2) CheckBox 상속한 Custom View에서 onRestoreInstanceState 수정

public class MyCheckbox extends CheckBox {
    public IBCheckbox(Context context) {
        super(context);
    }

    public IBCheckbox(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public IBCheckbox(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void onRestoreInstanceState(Parcelable state) {
        final CharSequence text = getText(); // the text has been resolved anew
        super.onRestoreInstanceState(state); // this restores the old text
        setText(text); // this overwrites the restored text with the newly resolved text
    }
}

 

 

 

 

참고:

https://stackoverflow.com/questions/4504024/android-localization-problem-not-all-items-in-the-layout-update-properly-when-s

 

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

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 radio buttons that hav...

stackoverflow.com

https://android-review.googlesource.com/c/platform/frameworks/base/+/67850

 

https://android-review.googlesource.com/c/platform/frameworks/base/+/67850

 

android-review.googlesource.com