The Edittext long press in popupwindow does not show the input method selection box

Source: Internet
Author: User

References:

1. The Edittext long press in popupwindow does not show the input method selection box

Http://www.eoeandroid.com/thread-93841-1-1.html

2. Edittext cannot be copied or pasted.

Http://www.eoeandroid.com/thread-283339-1-1.html

3. edit text by pressing the context menu

Http://www.apkbus.com/android-32266-1-1.html

4. Use of the Android drop-down box (Spinner)

Http://imshare.iteye.com/blog/770950

5. In Android, only the copy and paste menu is displayed with a long press on EditText. Do not bring up the following input method keyboard. How can this problem be solved?

Http://zhidao.baidu.com/link? Url = jdTB-CGbGDRZ3-acjhwDdSXjX4NoJkhbpjej7_EMlOkz8nQS4Z2y34SLYQfUPudg9RzbRwAZiCUtClpFAUNPPRd3LI_NBH-8GcyTUa3KU9 _

6. edit text after long-pressing EditText

Http://www.myexception.cn/android/347197.html

7. android UI advanced pop-up window 2) -- realize pop-up window effect of address book

Http://blog.csdn.net/notice520/article/details/6691246

8. Disable default selection for the Spinner.

Http://jiangsy1107.blog.sohu.com/174405573.html

9. How to cancel default selection of a Spinner

Http://www.eoeandroid.com/thread-40548-1-1.html

10. dynamically Add/delete a menu for a spindle in Android

Http://android.tgbus.com/Android/tutorial/201105/352290.shtml

11. How to hide one item in an Android Spinner

Http://stackoverflow.com/questions/9863378/how-to-hide-one-item-in-an-android-spinner


Android. view. WindowManager $ BadTokenException: Unable to add window -- token null is not for an application

Change Statement 1 to Statement 2! As follows:

Statement 1: context = getActivity (). getApplicationContext ();

Statement 2: context = getActivity ();

Reference link:

Http://blog.csdn.net/wsz1z154/article/details/7724912


Run the following code to implement long-pressed EditText in PopupWindow to bring up the spinner list.

Final String [] options = {"all selected", "cut", "copy", "Paste"}; final Spinner spinner = (Spinner) view. findViewById (R. id. spinner); ArrayAdapter <String> adapter = new ArrayAdapter <String> (context, android. r. layout. simple_spinner_item, options); adapter. setDropDownViewResource (android. r. layout. simple_spinner_dropdown_item); spinner. setAdapter (adapter); spinner. setOnItemSelectedListener (new AdapterView. onItemSelectedList Ener () {@ Override public void onItemSelected (AdapterView <?> Parent, View view, int position, long id) {ToastUtil. show ("you select>" + options [position]) ;}@ Override public void onNothingSelected (AdapterView <?> Parent) {}}); popWin. setTouchInterceptor (new View. onTouchListener () {@ Override public boolean onTouch (View v, MotionEvent event) {editText. setOnLongClickListener (new OnLongClickListener () {public boolean onLongClick (View v) {Logger. v (TAG, "editText long click"); // InputMethodManager imm = (InputMethodManager) context //. getSystemService (Context. INPUT_METHOD_SERVICE); // imm. showInputMethodPicker (); spinner. optional mclick (); return false ;}});

Use the reflection mechanism to call private methods of the system class

try {    Class<EditText> cls = EditText.class;    Method setSoftInputShownOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class);    setSoftInputShownOnFocus.setAccessible(true);    setSoftInputShownOnFocus.invoke(editText, false);} catch (Exception e) {    e.printStackTrace();}


After a drop-down list is displayed, you cannot add options to the adapter. Otherwise, an exception occurs.

1. java. lang. NoSuchMethodError: android. widget. ArrayAdapter. addAll

2. java. lang. UnsupportedOperationException


Dynamic Structure of the long press text box pop-up options

Private List <String> getOptionList (EditText editText) {List <String> optionList = new ArrayList <String> (); boolean select = false; boolean cut = false; boolean copy = false; boolean paste = false; boolean inputmethod = true; ClipboardManager clipBoard = (ClipboardManager) context. getSystemService (Context. CLIPBOARD_SERVICE); int start = editText. getSelectionStart (); int end = editText. getSelectionEn D (); cut = copy = (start! = End); paste = clipBoard. hasText (); select = (! EditText. getText (). toString (). isEmpty (); optionList. add (""); if (select) {optionList. add ("select all");} if (cut) {optionList. add ("cut");} if (copy) {optionList. add ("copy");} if (paste) {optionList. add ("");} if (inputmethod) {optionList. add ("Input Method");} return optionList;} private String [] getOptions (EditText editText) {List <String> optionList = getOptionList (editText ); string [] options = new String [optionList. size ()]; for (int I = 0; I <options. length; I ++) {options [I] = optionList. get (I);} return options ;}

Hide an option using the custom ArrayAdapter

public class CustomAdapter extends ArrayAdapter<String> {     private int hidingItemIndex;     public CustomAdapter(Context context, int textViewResourceId, String[] objects, int hidingItemIndex) {         super(context, textViewResourceId, objects);         this.hidingItemIndex = hidingItemIndex;     }     @Override     public View getDropDownView(int position, View convertView, ViewGroup parent) {         View v = null;         if (position == hidingItemIndex) {             TextView tv = new TextView(getContext());             tv.setVisibility(View.GONE);             v = tv;         } else {             v = super.getDropDownView(position, null, parent);         }         return v;     } }private ArrayAdapter<String> getSpinnerAdapter(EditText editText) {    String[] options = getOptions(editText);    int hidingItemIndex = 0;    CustomAdapter dataAdapter = new CustomAdapter(context, android.R.layout.simple_spinner_item, options, hidingItemIndex);    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);    return dataAdapter;}


Long press text box displays the spinner drop-down list

Final EditText editText = (EditText) view. findViewById (R. id. comment_et); editText. setText (textView. getText (); final Spinner spinner = (Spinner) view. findViewById (R. id. spinner); spinner. setPrompt ("edit text"); spinner. setOnItemSelectedListener (new AdapterView. onItemSelectedListener () {@ Override public void onItemSelected (AdapterView <?> Parent, View view, int position, long id) {String text = spinner. getAdapter (). getItem (position). toString (); if (! Text. equals ("") {ToastUtil. show (text) ;}@ Override public void onNothingSelected (AdapterView <?> Parent) {}}); editText. setOnLongClickListener (new OnLongClickListener () {public boolean onLongClick (View v) {Logger. v (TAG, "editText long click"); spinner. setAdapter (getSpinnerAdapter (editText); spinner. optional mclick (); return false ;}});


EditText in PopupWindow does not support text editing: select text, select all, cut, copy, and paste.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.