开发者

Problems accessing my strings.xml items.... i got numbers and not the string value

when from a java class i try to acces a item of my strings.xml file, i got numbers, like a mem position, and i dont get the string value of the item

for example:

if (parent.getItemAtPosition(pos).toString().equals(R.string.perdayspermission))

th开发者_开发技巧is code: R.string.perdayspermission haves to give me "Per Days", but it gives me a extrange number: 234552634

why?


Use getString() e.g.,

if (parent.getItemAtPosition(pos).toString().equals(getString(R.string.perdayspermission)))


Thats because R.string.perdayspermission is simply a numerical reference to where that string can be found. Try:

if (parent.getItemAtPosition(pos).toString().equals(getResources().getString(R.string.perdayspermission))

Update:

String item = parent.getItemAtPosition(pos).toString();
String test = getResources().getString(R.string.perdayspermission);
Log.i('test', 'item: '+item);
Log.i('test', 'test: '+test);
if(item.compareTo(test)==0)Log.i('test', 'strings match');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜