Thursday, 15 April 2010

android - Localization Through Application Class? -



android - Localization Through Application Class? -

i implementing localization illustration through app. used application class update selected language entire application. issue when alter language @ first time it's changing entire application. 1 time again when trying alter language it's giving forcefulness close error.the error @ line editor.putstring("language", getstring(identifier)); below code , logcat errors. not understanding how prepare this.

@override public void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); textview mtextview = (textview) v.findviewbyid(android.r.id.text1); toast.maketext(getactivity(), mtextview.gettext().tostring(), toast.length_short).show(); int identifier = getresources().getidentifier( mtextview.gettext().tostring(), "string", getactivity().getpackagename()); string language = getstring(identifier); toast.maketext(getactivity().getapplicationcontext(), language, toast.length_short).show(); editor.clear(); editor.putstring("language", getstring(identifier)); editor.commit(); changelanguage(getstring(identifier)); } /** * method alter language * * @param localstring */ public void changelanguage(string localstring) { allupdateapplication.updatelanguage(getactivity().getapplicationcontext()); } public class allupdateapplication extends application{ /** * application wide language alter * @param mcontext */ public static void updatelanguage( context mcontext){ sharedpreferences muwbtprefs = mcontext.getsharedpreferences("language", 0); string mlanguage = muwbtprefs.getstring("language", "en"); //toast.maketext(mcontext,mlanguage, toast.length_short).show(); configuration mconfiguration = new configuration(); mconfiguration.locale = new locale(mlanguage); mcontext.getresources().updateconfiguration(mconfiguration, null); } } 02-18 15:30:28.660: e/androidruntime(6819): fatal exception: main 02-18 15:30:28.660: e/androidruntime(6819): android.content.res.resources$notfoundexception: string resource id #0x0 02-18 15:30:28.660: e/androidruntime(6819): @ android.content.res.resources.gettext(resources.java:247) 02-18 15:30:28.660: e/androidruntime(6819): @ android.content.res.resources.getstring(resources.java:331) 02-18 15:30:28.660: e/androidruntime(6819): @ android.support.v4.app.fragment.getstring(fragment.java:593) 02-18 15:30:28.660: e/androidruntime(6819): @ com.uwbt.fragments.languagesfragment.onlistitemclick(languagesfragment.java:89) 02-18 15:30:28.660: e/androidruntime(6819): @ android.support.v4.app.listfragment$2.onitemclick(listfragment.java:58) 02-18 15:30:28.660: e/androidruntime(6819): @ android.widget.adapterview.performitemclick(adapterview.java:292) 02-18 15:30:28.660: e/androidruntime(6819): @ android.widget.abslistview.performitemclick(abslistview.java:1058) 02-18 15:30:28.660: e/androidruntime(6819): @ android.widget.abslistview$performclick.run(abslistview.java:2514) 02-18 15:30:28.660: e/androidruntime(6819): @ android.widget.abslistview.ontouchevent(abslistview.java:3180) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.view.dispatchtouchevent(view.java:5545) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1951) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1712) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1726) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1726) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1726) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1726) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1726) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1726) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1726) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1726) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1726) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1726) 02-18 15:30:28.660: e/androidruntime(6819): @ com.android.internal.policy.impl.phonewindow$decorview.superdispatchtouchevent(phonewindow.java:1912) 02-18 15:30:28.660: e/androidruntime(6819): @ com.android.internal.policy.impl.phonewindow.superdispatchtouchevent(phonewindow.java:1371) 02-18 15:30:28.660: e/androidruntime(6819): @ android.app.activity.dispatchtouchevent(activity.java:2391) 02-18 15:30:28.660: e/androidruntime(6819): @ com.android.internal.policy.impl.phonewindow$decorview.dispatchtouchevent(phonewindow.java:1860) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.view.dispatchpointerevent(view.java:5725) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewrootimpl.deliverpointerevent(viewrootimpl.java:2928) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewrootimpl.handlemessage(viewrootimpl.java:2492) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewrootimpl.processinputevents(viewrootimpl.java:870) 02-18 15:30:28.660: e/androidruntime(6819): @ android.view.viewrootimpl.handlemessage(viewrootimpl.java:2501) 02-18 15:30:28.660: e/androidruntime(6819): @ android.os.handler.dispatchmessage(handler.java:99) 02-18 15:30:28.660: e/androidruntime(6819): @ android.os.looper.loop(looper.java:137) 02-18 15:30:28.660: e/androidruntime(6819): @ android.app.activitythread.main(activitythread.java:4424) 02-18 15:30:28.660: e/androidruntime(6819): @ java.lang.reflect.method.invokenative(native method) 02-18 15:30:28.660: e/androidruntime(6819): @ java.lang.reflect.method.invoke(method.java:511) 02-18 15:30:28.660: e/androidruntime(6819): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 02-18 15:30:28.660: e/androidruntime(6819): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 02-18 15:30:28.660: e/androidruntime(6819): @ dalvik.system.nativestart.main(native method)

i think define language specific value folder.

android

No comments:

Post a Comment