Reputation:
In my integer.xml
I have
<integer name="minUNameLen">6</integer>
And in my code I am :
if (uName.trim().length() < R.integer.minUNameLen) {
Toast.makeText(
Splash.this.getApplicationContext(),
"Should be Min "+R.integer.minUNameLen+" characters long",Toast.LENGTH_LONG).show();
But instead of returning 6
I am getting 2131165….
a weird number in my code.
Can anybody tell what’s wrong in here?
Doing Resources.getInteger(R.integer.minUNameLen)
from here gives me Cannot make a static reference to the non-static method getInteger(int) from the type Resources
Upvotes: 0
Views: 135
Reputation: 7315
You need a Context
object instance to retrieve a Resources
object instance and finally get the desired resource, an Integer in your case.
myActivity.getContext().getResources().getInteger(R.integer.yourIntegerID);
as Activity
extends Context
you can simply call
myActivity.getResources().getInteger(R.integer.yourIntegerID);
Upvotes: 0
Reputation: 15533
Use getResources().getInteger(R.integer.minUNameLen)
to get the value
Upvotes: 1
Reputation: 522
What you are getting is the value of the variable R.integer.minUNameLen
What you need is: Activity.getResources().getInteger(R.integer.minUNameLen)
Upvotes: 0
Reputation: 17402
That's the resource ID you're seeing.
You need to use
getResources().getInteger(R.integer.minUNameLen)
Upvotes: 1