-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
  • 773
  • 9
  • 25
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,382
  • 2
  • 13
  • 28
0

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

AskNilesh
  • 63,753
  • 16
  • 113
  • 150
Jay Thakkar
  • 1,274
  • 9
  • 18