Introduzca la clave que comienza una nueva línea en EditText en lugar de enviar el texto (Android)
Tengo una aplicación todolist simple que estoy creando por lo que nuevos elementos de todo se agregan a través de una vista EditText. Así que estoy tratando de tener que enviar el nuevo elemento a la lista cuando presiono la tecla Intro . Por alguna razón, aunque acaba de introducir una nueva línea en su lugar . También he notado que funciona bien cuando uso la tecla de entrada a través de un AVD a través de eclipse, pero el problema sólo se produce cuando estoy corriendo a través de mi Nexus 4.
Aquí está mi código:
- Respecto al texto de edición, complete el borde
- Android OS bug con algunos dispositivos que ejecutan Jelly Bean / 4.2.1 - TextView.setError (error CharSequence) Icono que falta
- Agregar cadena no editable a EditText
- Mejor manera de obtener todo el texto en un EditText de un InputConnection?
- Editar el foco de texto en android
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.todo_main); //Create reference to the ListView in the main layout ListView myListView = (ListView)findViewById(R.id.myListView); //Create a reference to the EditText view in the main layout for adding new items final EditText editText = (EditText)findViewById(R.id.myEditText); //Create a an arraylist to hold all the todo items final ArrayList<String> todoList = new ArrayList<String>(); //Create an ArrayAdaptor object to be able to bind ArrayLists to ListViews final ArrayAdapter<String> arrayAdaptor = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, todoList); myListView.setAdapter(arrayAdaptor); //Listens for certain keys to be pushed, particular the dpad center key or enter key editText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if(event.getAction() == KeyEvent.ACTION_DOWN) { if((keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER)) { //add item in the EditText to the todo list todoList.add(0, editText.getText().toString()); //Update the view by notifying the ArrayAdapter of the data changes arrayAdaptor.notifyDataSetChanged(); editText.setText(""); return true; } return false; } return false; } }); }
Y XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ToDoListActivity"> <EditText android:id="@+id/myEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/addItemHint" android:imeOptions="actionDone" /> <ListView android:id="@+id/myListView" android:layout_width="match_parent" android:layout_height="wrap_content" />
Tenga en cuenta que he encontrado preguntas similares sobre el desbordamiento de pila, pero ninguno parecen resolver mi problema. ¡He intentado!
- Android EditText ninguna entrada con external blueTooth Hardware Keyboard
- Cómo cambiar el enfoque a la siguiente edición de texto en android?
- Multiline EditText con IMEOption Siguiente en android
- ExpandableListView con un EditText
- Cómo alinear a la derecha el texto en un Android TextView o EditText?
- Prevención del enfoque automático de EditText en un AlertDialog
- Etiqueta en un cuadro de edición en android
- Vista de texto editable al hacer clic
Establezca la propiedad singleLine en el widget EditText como true:
<EditText android:singleLine="true" android:id="@+id/myEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/addItemHint" android:imeOptions="actionDone" />
android:inputType="textMultiLine"
La adición de esta propiedad en edittext resolverá el problema
android:inputType="textImeMultiLine"
En mi caso esto ha resuelto el problema!
Android: singleLine = "true" es depricated, use
Android: maxLines = "1"
Android: inputType = "texto"
Android: imeOptions = "actionNext"
- Android: "Actualizar automáticamente" después de un tiempo determinado
- Onclick en paginador de vista en android no funciona en mi código