YankeeSierra
YankeeSierra

Reputation: 55

Displaying text from 2 other TextViews gives a surprising output

I have 2 TextViews. 1 get's the score from the first half (ScoreHelft) and the second TextView from the second half (ScoreEind).

ScoreHelft.setText(String.valueOf(counterThuis) + " - " + String.valueOf(counterUit));

This gives a result as expected, for example: 0 - 0

I now have 2 TextViews with 2 scores, for example: 0 - 0 and 1 - 1. This part works.

However, when I want to put those 2 together into an other TextView, which I want to combine the 2 results into a TextView that shows:

0-0 (1-1)

I used this code:

results.setText(ScoreHelft + " (" + ScoreEind + ")");

Now this doesn't work as I expected. If I print the output it gives me what's quoted below, plus pretty much the same kind of text, but ending on app:id/ScoreHelft and app:id/ScoreEind. But it only prints those extra things on the screen, not in the Monitor for some reason.

android.support.v7.widget.AppCompatTextView{b91f78 V.ED..... ......ID 32,713-147,751 #7f0d0085 app:id/results

.

I was wondering what I'm doing wrong to get this output.

Upvotes: 3

Views: 67

Answers (1)

Pavneet_Singh
Pavneet_Singh

Reputation: 37404

You cannot pass view references to setText function

setText(ScoreHelft + " (" + ScoreEind + ")"

where ScoreHelft and ScoreEind are TextView references so you need to fetch the text using yourTextView.getText().toString() function

results.setText(ScoreHelft.getText().toString() + " (" + ScoreEind.getText().toString() + ")");

Upvotes: 2

Related Questions