Error using values string

Asked

Viewed 53 times

1

Hello, I’m using string within values.

Everything is working fine, but when the phrase is composed of something that comes from the bank (for example) and a string, it is putting numbers instead of text.

numeroAvaliacoes.setText(" " + object.getInt("avaliacoes") + R.string.avaliacoesesp);

Someone knows how to fix this?

I know I could put two Textviews, but there are things (for example the share Intent that would have to put together.

Thank you

2 answers

2

It turns out that R.string.avaliacoesesp is a Resource.

Do so:

numeroAvaliacoes.setText(" " + object.getInt("avaliacoes") + getResources().getString(R.string.avaliacoesesp));

2


The class TextView has the method setText overloaded in various ways (Follows the documentation):

You can pass the id (Resid) of a String, and also the String (Charsequence) in itself, among other forms.

If you concatenate the id with a String, she considers the value of id (transforms the value into String)

In your case, you need to turn your id into String, so you can concatenate !

For this purpose it uses the method getString of Context.

follows an example:

numeroAvaliacoes.setText(" " + object.getInt("avaliacoes") +getContext().getString( R.string.avaliacoesesp ));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.