Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setText to a variable

I'm having trouble creating a simple app, I created a variable that changes when you click a button, but I would like to know how to set my TextView to that variable.

total is my TextView, and count is my variable.

I am trying total.setText(count);

I dont know how to tell it to just take the value of count and set the text to that.

Any help would be greatly appreciated.

like image 846
user888712 Avatar asked Nov 22 '25 14:11

user888712


1 Answers

First, you need to give your TextView an ID in the layout file:

<TextView
    <!-- existing code -->
    android:id="@+id/total">
</TextView>

Then use something like this to get the instance of the TextView and set the text:

TextView total = (TextView) findViewById(R.id.total);
total.setText(Integer.toString(count));
like image 53
Mike Avatar answered Nov 25 '25 05:11

Mike



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!