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');
精彩评论