java - NoSuchMethodError Exception with SetLocale -


in xamarin, have created following extension change locale on fly:

public static void toenglishlocale(this activity activity) {     locale locale = new locale("en-us");     configuration config = new configuration();     config.setlocale(locale);     activity.basecontext.resources.updateconfiguration(config, activity.basecontext.resources.displaymetrics); } 

i targeting api 15 , fails following exception on api 15:

unhandled exception:  java.lang.nosuchmethoderror: no method name='setlocale' signature='(ljava/util/locale;)v' in class landroid/content/res/configuration; 

is there other "unified" way change locale on fly? thanks!

the method setlocale added in api level 17 that's why getting error.

you can use android.os.build.version.sdkint property find api version @ runtime , call method if android.os.build.version_codes.jellybeanmr1 or newer. if isn't should set locale public property instead of calling setlocale


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -