Error using string of values

1

Hello, I'm using string within values.

It's all working fine, but when the sentence is made up of something that comes from the bank (for example) and a string, it's putting numbers instead of text.

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

Does anyone know how to solve this?

I know I could put two TextViews, but there is something (for example the Intent of share that would have to put together anyway.

Thank you

    
asked by anonymous 12.12.2016 / 14:05

2 answers

2

The TextView class has the setText method overloaded in several ways ( Follows the documentation a>):

You can pass the id ( resId ) of a String, and also the String ( CharSequence ) itself, between other forms.

If you concatenate the id with a String , it considers the value of id (turns the value into String)

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

This uses the getString method of Context .

follows an example:

numeroAvaliacoes.setText(" " + object.getInt("avaliacoes") +getContext().getString( R.string.avaliacoesesp ));
    
12.12.2016 / 14:20
2

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

Do this:

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