-1

I have this code for sending a text is selected from first textView to second textView with clicking on a button :

txt=(TextView)findViewById(R.id.txt);
        txt2=(TextView)findViewById(R.id.txt2);
        btn=(Button)findViewById(R.id.btn);
        final int startIndex = txt.getSelectionStart();
        final int endIndex = txt.getSelectionEnd();
        final String stringYouExtracted = txt.getText().toString().substring(startIndex, endIndex);
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        clipboard.setText(stringYouExtracted);

        btn.setOnClickListener(new OnClickListener() {


            public void onClick(View arg0) {
                 txt2.setText(stringYouExtracted);


            }
        });

but when I press button nothing send to txt2 and txt2 is empty .... why ??

I think txt2.setText(stringYouExtracted) is wrong but I am very biginner and I can't fix it ????

Is public CharSequence getCharSequence (String key) a solution ?? if yes help me because I don't know how can I use it ????

Ehsan
  • 5
  • 8
  • 2
    What exactly you want to do ? – InnocentKiller Apr 01 '14 at 08:40
  • I want select in a first textview and then clipboard_service will enabe ...... and I have another textview ,,,,, so the user has two option ..... first choose from clipboard .... second press the button and see his selected text from first textview in second textview – Ehsan Apr 01 '14 at 08:49

1 Answers1

0

Try this...

Get the all text value inside ClickListener when application launch all the text are empty

    btn.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
             final int startIndex = txt.getSelectionStart();
             final int endIndex = txt.getSelectionEnd();
             final String stringYouExtracted = txt.getText().toString().substring(startIndex, endIndex);
             ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
             clipboard.setText(stringYouExtracted);
             txt2.setText(stringYouExtracted);
        }
    });
Hariharan
  • 24,741
  • 6
  • 50
  • 54
  • with your code I think everything works with pressing button .... I want just set the text of second textview with button and copy to clipboard isn't related to button – Ehsan Apr 01 '14 at 08:44
  • @user3484190 without ClickListener you cannot get particular text. – Hariharan Apr 01 '14 at 08:50
  • I want select in a first textview and then clipboard_service will enabe ...... and I have another textview ,,,,, so the user has two option ..... first choose from clipboard .... second press the button and see his selected text from first textview in second textview – Ehsan Apr 01 '14 at 08:53