First of all add this property in textview in your xml : -
android:textIsSelectable="true"
Then use this code :-
t = (TextView)findViewById(R.id.textView1);
t.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
int start = t.getSelectionStart();
int end = t.getSelectionEnd();
if(start == -1 && end == -1){
return true;
}
String mSelectedText=((TextView)v).getText().toString().substring(start, end);
System.out.println(mSelectedText);
return false;
}
});