-1

Following is my code

 public void display(int number){
        TextView quantity = findViewById(R.id.quantity);
        quantity.setText(number);
    }

When I give setText(number) then it gives error which states that no resource found. But when I give setText("" + number); then it works perfectly. Am I missing some fundamentals?

Shruti
  • 803
  • 9
  • 26
Deep Gosalia
  • 187
  • 1
  • 1
  • 6

2 Answers2

1

Try This

public void display(int number){
    TextView quantity = findViewById(R.id.quantity);
    quantity.setText(String.valueOf(number));
}
Sniffer
  • 1,495
  • 2
  • 14
  • 30
0

setText() only accepts String value and int number is a number so we have convert it to string.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Jay Thakkar
  • 1,392
  • 10
  • 19