Normally i am 开发者_如何学Gousing getString(R.string.) to query strings in xml file. Is there any way to query xml file via getString(""). Because in my code i want to load the string present in resource file dynamically according to the condition. Any help would be really useful for me in learning android.
-Regards, Ron..
You can retrieve the id of a string resource dynamically as follows:
int resId = getResources().getIdentifier("key_name", "string", getPackageName());
Log.d("MyApp", "resource id is " + resId + " and value is " + getString(resId));
Where key_name is the name of a string in your strings.xml.
I hope I have understood your question correctly.
精彩评论