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?
- !!! JUnit versión 3.8 o posterior esperado
- CalendarView no muestra los días del mes
- android esperando respuesta del servidor
- Cómo resolver este error VFY: no se puede resolver el método virtual
- Android Bluetooth status 133 en onCharacteristicwrite
- android Apache httpclient archivo de carga ,. tiene algún error de reensamble TCP extraño
- VideoView no reproduce video o audio en RecyclerView
- Localización de recursos en la aplicación android
- ¿Cómo detectar cuando la batería es baja: Android?
- La configuración de libGDX me permite usar Java 8 que se bloquea en Android
- Hilo de fondo que bloquea la interfaz de usuario durante varios segundos
- GetStaticMethodId firma de método para public static MyClass myMethod ()
- ¿Cómo obtener una vista desde dentro de Espresso para pasar a un IdlingResource?
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