开发者

Determining if an Android preference was set previously

I have an app which will have the UI text in different languages. I do not want to save this in the strings.xml, because I want the user to be able to change them (and not be dependant on the phone's locale).

I've setup a preference to read this. By default, I want the UI to take the locale value, but 开发者_JS百科if the user has changed the UI lang preference, I want it to use that.

Is there any way to determine if a preference has been set previously? The thing is, the getInt makes me set a default, so I can't check (for example) that uiLang==null to determine if a preference was set before or not.

SharedPreferences settings = getPreferences(MODE_PRIVATE);
//If uiLang has not been set before, then lets use the locale.
uiLang = settings.getInt("uiLang", 1);  //English (=1) es default
myUI = new UIText(uiLang);
myTextView.setText(myUI.title);


you could use the 'contains' method to check this:

http://developer.android.com/reference/android/content/SharedPreferences.html#contains%28java.lang.String%29

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜