user3296057
user3296057

Reputation: 23

How to add variable integer in String number" ";

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;
    }
}

Upvotes: 0

Views: 136

Answers (4)

Hamid Shatu
Hamid Shatu

Reputation: 9700

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;
    }
}

Upvotes: 0

FD_
FD_

Reputation: 12919

In your case, I think you want:

String number = String.valueOf(phone);

Or

String number = "" + phone;

Or

String number = Integer.toString(phone);

Upvotes: 1

M Sach
M Sach

Reputation: 34424

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)

Upvotes: 0

Ajay S
Ajay S

Reputation: 48612

You can do like this.

String str = String.valueOf(9900990)

Upvotes: 2

Related Questions