0

I'm new to programming. I am learning how to add variable integer with String number = " "; below is an example. I'm testing.

Button buttonSend;
int phone =9900990;

public void onClick(View v) {  
    switch (v.getId()) {     
        case R.id.buttonSend:     
            String messageToSend = "#abc";
            String number = " ";
            SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null, null);
            break;
    }
}
3
  • 6
    What is your question? Commented Feb 15, 2014 at 15:33
  • 1
    You shouldn't keep a phone number as an int. The best format is a string. Imagine the number starts with 0; as an int, the number will lose any leftmost zeros. Commented Feb 15, 2014 at 15:39
  • @Piovezan - thank you for the advice. I did not even know about this. It is very useful info to me Commented Feb 15, 2014 at 16:26

4 Answers 4

2

You can do like this.

String str = String.valueOf(9900990)
Sign up to request clarification or add additional context in comments.

Comments

1

In your case, I think you want:

String number = String.valueOf(phone);

Or

String number = "" + phone;

Or

String number = Integer.toString(phone);

Comments

0
Button buttonSend;
int phone =9900990;

public void onClick(View v) {  

    switch (v.getId()) {     

        case R.id.buttonSend:     
             String messageToSend = "#abc";
             String number = " " + phone;

             SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
             break;
    }
}

Comments

0

Below is the stuff you are looking for(as per feeling from your question)

String number = " " + 9900990;

But cleaner way is to convert integer to string

 String str = String.valueOf(9900990)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.