Use values of strings.xml

1

I have this code in the string.xml

<?xml version="1.0" encoding="utf-8"?>
    <resources>
         <string name="hint_input_user_es">EMAIL:</string>
    </resources>

And what I want is to get "EMAIL" and show it in a textView as Hint. I've tried it in several ways and it all gives me the same error.

TextView login_email = (TextView) findViewById(R.id.login_email);

1. login_email.setHint(getText(R.string.hint_input_user_es));
2. login_email.setHint(getResources().getString(R.string.hint_input_user_es));
3. login_email.setHint(getString(R.string.hint_input_user_es));

And in all cases I get this error:

android.content.res.Resources$NotFoundException: String resource ID #0x7f05002b

Thank you very much.

    
asked by Deivis González González 04.05.2017 в 22:10
source

2 answers

2

I got to try this code and it worked correctly

TextView hint = (TextView) findViewById(R.id.textView2);
String hint2 = getResources().getString(R.string.hint2);
hint.setHint(hint2);

<resources>
    <string name="hint2">HINT2</string>
</resources>

But it seems to me that the TextView, even if it has a Hint field, does not apply for that information to be displayed on the screen.

<TextView
    android:id="@+id/textView"
    android:hint="@string/hint"
    android:text="TextView"/>

Maybe you might think more about an EditText? Since in the EditText when there is nothing written, it shows the Hint

 <EditText
     android:id="@+id/editText"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:hint="@string/hint"/>

Note: I tried the same code with an EditText and it also works

    
answered by 04.05.2017 / 22:42
source
-2

The value of the "hint" or text, can be set without problem prográmaticamente:

myEditText.setHint("Escribe algo!");

or directly in sight.

 <EditText
     android:id="@+id/editText"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:hint="Escribe algo!"/>

Regarding the error:

  

android.content.res.Resources $ NotFoundException: String resource ID    #0x7f05002b

At some point in your code you are assigning an integer value to either the setHint () or setText () method, you can test yourself to see what I'm saying.

I add a similar answer:

Error android.content.res.Resources $ NotFoundException: String resource ID # 0xbb8 on Android

    
answered by 04.05.2017 в 23:17