setText fails to show a number as text in a TextView
The problem is with lines like this
addAmount.setText(aAmt);
where aAmt
is an int
. This looks for a resource
with the id
of whatever aAmt
is. You need to cast it to a String
first like
addAmount.setText(String.valueOf(aAmt));
There are overloaded setText()
methods. See the docs
This post goes into some more detail as to how this actually works
setText not displaying the value to a TextView
just use
TextView days_int_remaining = (TextView) findViewById(R.id.days_int_remaining);
days_int_remaining.setText(String.valueOf(returning));
instead of
TextView days_int_remaining = (TextView) findViewById(R.id.days_int_remaining);
days_int_remaining.setText(returning);
why doesn't TextView set text work with int?
The problem is that you are calling setText(int resid)
instead of setText(CharSequence text)
. You can take a look at the documentation to understand more.
To solve this, you can convert the int
to String
by using String.valueOf()
:
private void punteggio(){
pntUno.setText(String.valueOf(pnt1));
pntDue.setText(String.valueOf(pnt2));
}
Android - Set text to TextView
In your layout XML:
<TextView
android:id="@+id/myAwesomeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Escriba el mensaje y luego clickee el canal a ser enviado"
android:textSize="20sp" />
Then, in your activity class:
// globally
TextView myAwesomeTextView = (TextView)findViewById(R.id.myAwesomeTextView);
//in your OnCreate() method
myAwesomeTextView.setText("My Awesome Text");
Related Topics
Android - Out of Memory Exception When Creating Bitmap
Android Hide/Unhide App Icon Programmatically
Using Viewpagerindicator Library with Android Studio and Gradle
Access the Http Response Headers in a Webview
Execution Failed for Task 'App:Mergedebugresources' Crunching Cruncher....Png Failed
Location Service Gps Force Closed
Disable Activity Slide-In Animation When Launching New Activity
Get JSONarray Without Array Name
How to Securely Store Credentials (Password) in Android Application
Android Navigation Drawer Toggle Icon to Right
Android Studio - Unable to Merge from Svn Branch
How to Make Constraintlayout Work with Percentage Values
Using Android Vector Drawables on Pre Lollipop Crash
How to Disable Past Dates in Android Date Picker
How to Display Progress Dialog Before Starting an Activity in Android
Navigation Drawer (Google+ VS. Youtube)
Android - Drawable with Rounded Corners at the Top Only
Android Emulator Error Message: "Panic: Missing Emulator Engine Program for 'X86' Cpus."