0

my problem is this: I have 2 text view, in the first a text that changes from "your X is" to "you are"("you are" is stored in a string) and in the latter a number that could assume any value or, if another value is "0", just become "perfect"(this took from a string). All this after a click on a button. The problem is that the first text changes while the second change from 0 but if the first value ( that i said before ) is 0 ( or minus 0 ) just doesn't change... It not assume the value of the string i want. I hope you got the problem, this is the code.

if (risultato <= 0) {
                    risultatoX.setText("0");
                    X.setText(R.string.youAre);
                    risultatoOre.setText(R.string.perfect);
                    risultatoOre.setTextColor(Color.parseColor("#259b24"));
                    hr.setVisibility(View.GONE);
                } else {
                    X.setText(R.string.First);
                    risultatoOre.setTextColor(Color.parseColor("#757575"));
                    hr.setVisibility(View.VISIBLE);
                }
3
  • Is there an exception being encountered? Commented Mar 18, 2015 at 17:08
  • 1
    Try getResources().getString(R.string.name); Commented Mar 18, 2015 at 17:18
  • Are you using an adapter? Try calling adapter.notifyDataSetChanged(); to force an update of the view Commented Mar 19, 2015 at 13:18

1 Answer 1

1

If you want to get String from resources you need use getResources().getString() method.

For example:

X.setText(getResources().getString(R.string.youAre));
risultatoOre.setText(getResources().getString(perfect));
Sign up to request clarification or add additional context in comments.

3 Comments

This is true if you are in an activity. If you are in a fragment, you will have to have a reference to the parent activity.
Then just use this code this.getParent().getResources().getString(R.string.youAre)
I solved, it was only a problem of the emulator, because on my mobile phone it is ok! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.