samedi 1 août 2015

Android Studio, use string.xml in java [duplicate]

This question already has an answer here:

I am using Android Studio. I have a strings.xml like this:

<string name="code01">Hello</string>
<string name="code02">Bye</string>
<string name="code03">Moon</string>
<string name="code04">Suun</string>

And at my XML, I have something like this:

<TextView android:id="@+id/code_a"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:typeface="monospace"
    android:textColor="#FFFFFF"/>

I want, that with a Java variable, to use one of these strings, on my XML. I tried this, at my OnCreate() Java function:

TextView var01;
var01 = (TextView)findViewById(R.id.code_a);
var01.setText("@string/code"+var02);

With var02 having possible values of "01", "02", "03", and "04". But this doesn´t work. What can I try?

Aucun commentaire:

Enregistrer un commentaire