Android setOnEditorActionListener () no se dispara

Estoy intentando fijar un oyente a EditText cuando el botón del enter será presionado. EditText no encendió en todos. He probado esto en LG Nexus 4 con Android 4.2.2. setOnEditorActionListener funciona en Amazon Kindle fuego con Android 2.3 y setImeActionLabel funciona en ninguna parte! También no puedo fijar el texto para el botón de la entrada. Aquí está el código:

 mEditText.setImeActionLabel("Reply", EditorInfo.IME_ACTION_UNSPECIFIED); mEditText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { Log.d("TEST RESPONSE", "Action ID = " + actionId + "KeyEvent = " + event); return true; } }); 

¿Qué estoy haciendo mal? ¿Cómo puedo arreglar esto?

Puede utilizar TextWatcher .

  editText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (s.charAt(s.length() - 1) == '\n') { Log.d("TEST RESPONSE", "Enter was pressed"); } } }); 

Asegúrese de que tiene un conjunto IME_ACTION en el archivo de diseño:

 <EditText android:id="@+id/search" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/search_hint" android:inputType="text" android:imeOptions="actionSend" /> 

Para obtener una explicación completa, consulte http://developer.android.com/guide/topics/ui/controls/text.html .

Puede probar esto para usar OnKeyListener

 editText.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int actionId, KeyEvent event) { Log.d("TEST RESPONSE", "Action ID = " + actionId + "KeyEvent = " + event); return false; } }); 

Lo tengo, funciona en Edittext en una actividad, pero no en un fragmento.

 <EditText android:id="@+id/mEditText" android:imeOptions="actionSearch" android:imeActionLabel="搜索" android:inputType="text" android:singleLine="true" android:textSize="18dp" android:paddingTop="5dp" android:paddingBottom="5dp" android:paddingLeft="3dp" android:paddingRight="3dp" android:textColor="@color/black" android:layout_marginTop="7dp" android:layout_marginBottom="7dp" android:shadowColor="#4b000000" android:shadowDy="1" android:shadowDx="1" android:shadowRadius="1" android:cursorVisible="true" android:textCursorDrawable="@null" android:gravity="center_vertical|left" android:background="@color/transparent" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" tools:ignore="UnusedAttribute"> <requestFocus/> </EditText> mEditText.setImeActionLabel("搜索", EditorInfo.IME_ACTION_SEARCH); mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { MToastUtil.show("搜索"); } return false; } }); 

asegurarse:

InputType = "text";

ImeOptions = "actionSend";

Después de un poco más de búsqueda – esta fue la solución para mí ( funciona también en un fragmento ):

Solo retira la imeAction

  • Barra lateral de Android como facebook o firefox
  • Android: Temporizador de cuenta atrás, por ejemplo, de 10:00 a 00:00? Utilizando OnclickListener a TextView?
  • Cómo crear un JSONObject de objetos? Androide
  • Cómo abrir la configuración GPS de un dispositivo Android?
  • Almacenamiento de un recurso de mapa de bits en una variable estática
  • Android WifiManager El subproceso nunca se cierra
  • ArrayList como variable global
  • Recortar o reemplazar todas las comas y espacios de la cadena
  • Android Facebook Login callback no funciona
  • ¿Por qué resource.getStringArray (int) lanzará una excepción?
  • Compartir código entre fragmentos
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.