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….ここで何が悪いのか誰にもわかりますか?


ここResources.getInteger(R.integer.minUNameLen)からやるとCannot make a static reference to the non-static method getInteger(int) from the type Resources

4

4 に答える 4

2

これが、表示されているリソース ID です。

使用する必要があります

getResources().getInteger(R.integer.minUNameLen)
于 2013-10-27T19:12:28.420 に答える
0

Contextオブジェクト インスタンスを取得し、Resources最終的に目的のリソース、場合によっては Integerを取得するには、オブジェクト インスタンスが必要です。

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

Activityextendsとして、Context単に呼び出すことができます

myActivity.getResources().getInteger(R.integer.yourIntegerID);
于 2013-10-27T19:29:19.360 に答える
0

あなたが得ているのは、変数の値R.integer.minUNameLen です必要なものは次のとおりです。Activity.getResources().getInteger(R.integer.minUNameLen)

于 2013-10-27T19:13:04.047 に答える