开发者

How to enumerate strings in a string resources file?

I have a resources file called string.xml in res/valus directory

the file has many string resources

how can I obtain these items in an array f开发者_如何学编程rom code ?

I tried

Field[] x=R.string.class.getFields();

but it does not work.

thanks


It works fine for me. You might detail your problem a little more though - what doesn't work? Note that the R.string class contains ints, not strings. Are you expecting strings? If you want a string from that resourceId int, call Context.getString(resourceId).


This is simple example of enumaration strings.You can use it.

Field[] fields = R.string.class.getFields();
    for(final Field field : fields) {
       String name = field.getName(); //name of string
       try{
           int id = field.getInt(R.string.class); //id of string
       }catch (Exception ex) {
           //do smth
       }
    }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜