开发者

Dynamically querying a String is Strings.xml file

开发者 https://www.devze.com 2023-03-10 19:14 出处:网络
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 re

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.

0

精彩评论

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