开发者

Android - referencing string array using another string to avoid using SQLite

开发者 https://www.devze.com 2023-04-07 14:39 出处:网络
I\'ve searched for this but I\'m not exactly sure what I should be searching for. I\'m trying to avoid using a SQLite DB and was wondering is it possible to call a string using the value of another s

I've searched for this but I'm not exactly sure what I should be searching for.

I'm trying to avoid using a SQLite DB and was wondering is it possible to call a string using the value of another string.

Eg.

If I have in a xml file this:

    <string-array name="bob">
<item>1</item>
<item>4</item>
<item>7</item>
<item>11</item>
</string-array>

And in a Java file this:

String name = "bob";

can I then do something like this:

String[] holder = getResources()开发者_开发技巧.getStringArray(R.array.name);

Thanks!


If I guess correctly what you are needing is getIdentifier(). Take into account that this method is expensive and it is much more efficient to retrieve resources by identifier.

0

精彩评论

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