Search code examples
androidlistviewcontextual-action-bar

ListView which allows long press for contextual menu, yet also allow selecting text


I'm not sure if this possible, but I'd like to somehow have text on rows of a List to be selectable for copying but also, long press to bring up a contextual menu.

I know that long press is required for selecting individual text, but its being overridden by the fact that I need to apply a long press to the entire row for displaying the contextual menu.

I'm sure others have come across this problem?

Edit: Ok, I just realised text can be selected by not only Long press but also, double click/press. So that can be used in this case instead


Solution

  • try this:

        yourEditText.setFocusableInTouchMode(false);
        yourEditText.setSelectAllOnFocus(true);
        yourEditText.clearFocus();
        yourEditText.setOnClickListener(new View.OnClickListener(){
    
            public void onClick(View v){
                yourEditText.requestFocusFromTouch();
            }
        });