Need to select the text from text view to desired range and do copy.I tried using onClick Listener on Text view and also i added android:textIsSelectable="true"
at xml
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView)findViewById(R.id.textview1);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
textView.setKeyListener(null);
textView.setFocusable(true);
String stringYouExtracted = textView.getText().toString();
int startIndex = textView.getSelectionStart();
int endIndex = textView.getSelectionEnd();
stringYouExtracted = stringYouExtracted.substring(startIndex, endIndex);
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(stringYouExtracted);
}
});
Toast.makeText(this, "Text clipped!", Toast.LENGTH_SHORT)
.show();
}
}
But it is not selecting the text and not getting the text to be copied