How to start contextual action bar for text view programmatically with default opions copy and select all?
Select your text manually and then perform a long click:
textView.post(new Runnable() {
@Override
public void run() {
Selection.selectAll((Spannable) tv.getText());
tv.performLongClick();
}
});
Edit:
The problem is that the built-in text selection CAB is private and uses multiple private classes. You'd need to copy a lot of code or access a bunch of methods with reflection to use it.
You could make your own CAB menu but you'd also need the controller handles which is again a lot of code.
A simple solution would be to live with what you have and use my above suggested method. If you want to avoid calling your long click listener you can remove it while calling the cab:
Selection.selectAll((Spannable) tv.getText());
tv.setOnLongClickListener(null);
tv.performLongClick();
tv.setOnLongClickListener(mLongClickListener);