EditText not showing default ContextMenu after long press

My EditText does not display the default ContextMenu (copy, paste, select, select) after a long press. Do I need to create my own ContextMenu?

Following are the snippets of the function called to create the popup menu that contains this EditText.

LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    popupView = layoutInflater.inflate(R.layout.add_recipe_pop,null);
    final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    EditText recipe_url = (EditText)popupView.findViewById(R.id.recipe_url_text);
    recipe_url.setLongClickable(true);
    registerForContextMenu(recipe_url);
    popupWindow.setFocusable(true);
    popupWindow.update();
    popupWindow.showAtLocation(v,Gravity.CENTER,0,0);

      

This is part of the add_recipe_pop XML file and the EditText is only in

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#E6E6E6"
    android:orientation="vertical" >

<EditText
     android:id="@+id/recipe_url_text"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:hint="@string/add_recipe_hint"
     android:inputType="textUri"
   />

      

I tried using EditText's focusable and setTextSelectable attribute, but the keyboard doesn't appear if I do that. Thanks for the help!:)

+3


source to share


2 answers


LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
popupView = layoutInflater.inflate(R.layout.add_recipe_pop,null);
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
EditText recipe_url = (EditText)popupView.findViewById(R.id.recipe_url_text);
popupWindow.update();
popupWindow.showAtLocation(v,Gravity.CENTER,0,0);

      

XML



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#E6E6E6"
android:focusable="true"   // toggle this when testing
android:orientation="vertical" >

<EditText
 android:id="@+id/recipe_url_text"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:hint="@string/add_recipe_hint"
 android:focusable="true"
 android:focusableInTouchMode="true"
 android:inputType="textUri"
/>

      

this should work ... i know if it works, so i give my reason.

0


source


This is deprecated, but for those looking at this, I found that it doesn't.

For whatever reason, any edit text inside the popup will work, but won't work with the copy / paste menu.

In fact, you can set any text you choose and it won't work.



The easiest way is to simply not use the popup menu. If you change your code to set the content view to the flyout menu layout it works.

Why doesn't it work in the popup menu I don't know, but not using the menu that works.

0


source







All Articles