0

My EditText in xml wrapped in LinearLayout:

 <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="TYPE HERE"
            android:padding="7dp"
            android:singleLine="true"
            android:cursorVisible="true"
            android:textIsSelectable="true"
            />

And in my fragment:

 mEditText.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                mEditText.requestFocus();
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);
                return true;
            }

Copy and paste feature doesn't work on the edit text ?? When I comment onTouchListener it works !

acbacbeaoclacm m cl adc a dcl arc ac a c amid ncoeocnejnlwencnajlendjlcejbcbaclbaldcblabdlbclabdclbladbclaelbclabdbcalebecam emac cjaecljabecbaebcjbec

Si8
  • 9,141
  • 22
  • 109
  • 221
DroidDev
  • 789
  • 9
  • 19
  • 1
    If you override the `onTouch` event, you will surely have an issue with copy/paste because that is handled in the `onTouch` event. Why do you need a *touch* listener on an EditText? Can you use *click* instead? – milosmns Oct 27 '16 at 21:06
  • Hey, Thanks. I didn't know its handled in onTouch event. – DroidDev Oct 27 '16 at 21:08
  • It's kinda what touch event is all about. I'm not 100% sure, but I think it's this line from the source: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/widget/TextView.java#8002 The same goes for EditText – milosmns Oct 27 '16 at 21:18

1 Answers1

1

From the source (http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/widget/TextView.java) it seems that onTouch events are handling the IME, keyboard, copy/paste, and similar operations. If you override those methods or provide custom listeners, make sure you handle the events yourself.

milosmns
  • 3,595
  • 4
  • 36
  • 48
  • EditText extends TextView, so it's pretty much the same thing around handling these events. – milosmns Oct 27 '16 at 21:35
  • I used onTouchListener() to show keyboard when edit text is tapped, Now how can i do that without overwriting onTouchListener()? – DroidDev Nov 08 '16 at 21:57
  • Keyboard will automatically pop up when you touch an EditText. If you actually need to override the touch event (and reconsider, because it can get messy), then you have to handle everything yourself (copy/paste/keyboard/etc) – milosmns Nov 08 '16 at 22:01
  • keyboard doesn't popup automatically . I have Editext inside a linear layout. I have also tried [link] http://stackoverflow.com/questions/5105354/how-to-show-soft-keyboard-when-edittext-is-focused but it doesn't work.. – DroidDev Nov 09 '16 at 16:21
  • If your keyboard doesn't pop up automatically, post another question and we'll take a look? It's probably not related to this problem. – milosmns Nov 09 '16 at 16:37