2013-10-27 40 views
0

在我integer.xml我有整數資源不能返回正確的值

<integer name="minUNameLen">6</integer> 

而且在我的代碼我:

if (uName.trim().length() < R.integer.minUNameLen) { 
       Toast.makeText(
         Splash.this.getApplicationContext(), 
         "Should be Min "+R.integer.minUNameLen+" characters long",Toast.LENGTH_LONG).show(); 

但不是返回6我得到2131165….一個奇怪的號碼在我的碼。 有人可以告訴這裏有什麼問題嗎?


否則從hereResources.getInteger(R.integer.minUNameLen)給我Cannot make a static reference to the non-static method getInteger(int) from the type Resources

回答

2

這就是你所看到的資源ID。

您需要使用

getResources().getInteger(R.integer.minUNameLen) 
0

你所得到的是可變R.integer.minUNameLen 你需要的值:Activity.getResources().getInteger(R.integer.minUNameLen)

2

使用getResources().getInteger(R.integer.minUNameLen)來獲取值

0

你需要一個Context對象實例來檢索一個對象實例並最終得到所需的資源,在你的情況下是一個Integer。

myActivity.getContext().getResources().getInteger(R.integer.yourIntegerID); 

Activity延伸Context,你可以簡單地調用

myActivity.getResources().getInteger(R.integer.yourIntegerID);