1

The purpose is to add functionality to a copy button on teh screen itself. What it does is it copies the text9 at that pint of time ) in the textview and copies that to the user's clipboard and hence making it available to forward that text and use it in other applications. What do I do?

#Java File.
package com.dreamgoogle.gihf;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

public class Quotes extends Activity {

    ImageButton next;
    ImageButton previous;
    ImageButton copytext;
    TextView q;
    TextView nm;
    String[] str;
    int i, s;

... 
.... 
.... 
... 
... 
... 





        copytext.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {










            }
        });
    }

q is the textview of whose text is to be copied.

code
  • 2,115
  • 1
  • 22
  • 46

3 Answers3

0

clipBorad manager available, but for api 11 onwards . no options i believe, for pre 11 devices . read here. additionally search for more examples.

Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
0

Use ClipBoardManager's setText method:

copytext.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {



//
    q = (TextView) findViewById(R.id.txt); // fetch the textview from the layout
    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
         ClipData clip = ClipData.newPlainText("label", q.getText().toString());
         clipboard.setPrimaryClip(clip);






            }
        });

Original Q / A

Community
  • 1
  • 1
Nezam
  • 4,122
  • 3
  • 32
  • 49
0

for only copy text put this code in your copytext.onclicklist.. method:

 ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
 ClipData clip = ClipData.newPlainText("label", ""+edittext.getText().toString());
 clipboard.setPrimaryClip(clip);
Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177