Maybe this solution will help you for provisioning both a menu or textselection.
I wanted text to be either selectable (for copy and paste) or wanted other gestures to work.
- Set textIsSelectable to false, either in the layout file or programmatically.
- Set an onTouchListener on the textview with your Gestures.
- Allow one of the gestures to switch to textSelection mode. See below.
How to set textSelection programmatically?
- Set the textIsSelectable, focusable, longPressable to true
- Set the onTouchListener to null.
- Install a click listener for switching back to the normal gestures / menu.
1) Install your GestureHandler:
// Create your Touch Listener
onTouchListener = new OnSwipeTouchListener(mCtx, this);
view.setOnTouchListener( onTouchListener);
2) Switch to textselction modus:
// Create your popup with an menu option to switch to textselection modus:
PopupMenu popup = new PopupMenu(mCtx, view);
popup.inflate(R.menu.text_options_menu);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case ...
case R.id.text_textisselectable:
view.setOnTouchListener(null);
((TextView)view).setTextIsSelectable( true);
((TextView)view).setFocusable( true);
((TextView)view).setLongClickable( true);
// Install a click listener to switch back to the previous Touch Listener
((TextView)view).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popupx = new PopupMenu(mCtx, view);
popupx.inflate(R.menu.selecttext_back_menu);
popupx.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
((TextView)view).setTextIsSelectable( false);
((TextView)view).setFocusable( false);
((TextView)view).setLongClickable( false);
view.setOnTouchListener(onTouchListener);
return true;
}});
popupx.show();
}
});
break;