Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 315
YankeeSierra Avatar asked Jan 20 '26 18:01

YankeeSierra


1 Answers

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() + ")");
like image 152
Pavneet_Singh Avatar answered Jan 22 '26 08:01

Pavneet_Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!