Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integer value in TextView

How can I display an Integer value in TextView?

When I try, I get an error android.content.res.Resources$NotFoundException: String resource ID

like image 350
Maya Avatar asked Oct 22 '10 06:10

Maya


People also ask

How can I get integer from TextView?

If you need to set an integer value, use tv. setText("" + 5) as setText() is an overloaded method that can handle string and int arguments. To get a value from tv use tv. getText() .

How do I add color to TextView?

There are two methods of changing the color of a TextView and the code for that has been given in both Java and Kotlin Programming Language for Android, so it can be done by directly adding a color attribute in the XML code or we can change it through the MainActivity File.

What is TextView?

A TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing.


2 Answers

TextView tv = new TextView(this); tv.setText(String.valueOf(number)); 

or

tv.setText(""+number); 
like image 107
Muhammad Abdullah Avatar answered Sep 20 '22 21:09

Muhammad Abdullah


TextView tv = new TextView(this); tv.setText("" + 4);
like image 35
Falmarri Avatar answered Sep 21 '22 21:09

Falmarri