MiKenning MiKenning -4 years ago 187
Android Question

Set Text to Integer Value

I want to set a

TextView
as the value of an integer, hopefully like so:

tv.setText(int)


However, the integer value is inside another class.

Answer Source

Inside another class? You can make a getter for the value you want in that class:

public int getValue() {
    return value;
}

So that you can access it from the other one:

tv.setText(theOtherClassInstance.getValue())

BUT if you set a TextView to an int, it will be interpreted as an Android resource id. If you want the value of the int as your text (and not the resource it points to), make it a String first.

tv.setText(String.valueOf(theOtherClassInstance.getValue()));

EDIT If your int is firstResult as per your comment below, then the getter becomes:

public int getFirstResult() {
    return firstResult;
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download