Skip to content

Android copy text from edittext

I’m having some trouble whilst following a beginner android dev program. I build an Android App and I have created EditText and Button.

My idea, users can put PhoneNumber in EditText, and if they click the Copy button, they can copy shortUrl with PhonNumber that inputed! So, I have create a String with Url. and if the users put the number will get it in the Url! Example:

users typed: +1716322765 if user click “The Button”, will get “”

So, I wrote this code, but does not execute.

    whatsLink = "";

    phoneNumber = (EditText) findViewById(;
    letsChatting = (Button) findViewById(;
    letsCopy = (Button) findViewById(;

    letsCopy.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {

            String copy = phoneNumber.getText().toString();
            if (copy.isEmpty()) {
                ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clipdata = ClipData.newPlainText("Data", phoneNumber.getText().toString());




You want if(!copy.isEmpty()). Otherwise you would only copy if there was no phone number entered.