0
I’m trying to get a string from the.xml string to replace a field on the screen, but I’ve been searching and I’m not being able to use it as a variable
xml string.
<string name="nome">%1$s</string>
java class.
Resources res = getResources();
String text = String.format(res.getString(R.string.nome), username);
xml layout.
<TextView
android:id="@+id/nome1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="@string/nome"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
Upshot:
Oh yes, so there’s no way to insert the data into the.xml string by the java class ?
– Matheus Rohwedder
Not that I know of.
– ramaral
Is that actually I tried to insert right into the field I show in the image, but it did not work
– Matheus Rohwedder
For when trying to insert the text, in that Textview the application 'crashava'
– Matheus Rohwedder
Right, so I would replace my xml with this one and it would supposedly trade?
– Matheus Rohwedder
I believe that your difficulty has nothing to do with your question. If what you want to know is how to change that Textview via java it is better to ask another question (not to invalidate this one) like: How to change Navigationview Headerview text?
– ramaral
Oh yes thank you, I was trying the way I asked the question, but you said it wouldn’t work
– Matheus Rohwedder