AutoCompleteTextView no muestra ningún elemento desplegable
Mi XML:
<AutoCompleteTextView android:id="@+id/searchAutoCompleteTextView_feed" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" android:completionThreshold="2" android:hint="@string/search" />
MI código java:
- AutocompleteTextview y CompletionHintView
- Cómo evitar que se llamen ambos: onItemClicked y onTextChanged en AutoCompleteTextView
- ¿La corrección automática no funciona con autocompletetextview?
- Android: AutoCompleteTextView margen superior en ListView
- Cómo cambiar el color de texto de la lista desplegable en un AutoCompleteTextView?
AutoCompleteTextView eT = (AutoCompleteTextView)findViewById(R.id.searchAutoCompleteTextView_feed); eT.addTextChangedListener(this); String[] sa = new String[]{"apple", "mango", "banana", "apple mango", "mango banana"}; ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, sa); eT.setAdapter(aAdapter);
Esto no está funcionando atall …. quiero decir su sólo funciona como un EditTextView. ¿Dónde estoy equivocado?
Código completo:
public class FeedListViewActivity extends ListActivity implements TextWatcher{ private AutoCompleteTextView eT; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.feed); eT = (AutoCompleteTextView) findViewById(R.id.searchAutoCompleteTextView_feed); eT.addTextChangedListener(this); Thread thread = new Thread(null, loadMoreListItems); thread.start(); } private Runnable returnRes = new Runnable() { public void run() { //code for other purposes } }; private Runnable loadMoreListItems = new Runnable() { public void run() { getProductNames(); // Done! now continue on the UI thread runOnUiThread(returnRes); } }; protected void getProductNames() { String[] sa = new String[]{"apple", "mango", "banana", "apple mango", "mango banana"}; ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_dropdown_item_1line, sa); eT.setAdapter(aAdapter); } public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } }
- Android: AutoCompleteTextView con sugerencias predeterminadas
- AutoCompleteTextView no reconoce espacios
- Virutas de material Android
- Los elementos de la caja desplegable de autocompletetextview de Android tienen una fuente grande
- Java.lang.NullPointerException - AutoCompleteTextView - HoneyComb
- Android AutoCompleteTextView sugiere alternativa
- El teclado oculta el menú desplegable AutoCompleteTextView
- Mostrar sugerencias de AutoCompleteTextView
Acabo de ver tu otra pregunta antes de ver esta. Yo estaba luchando con autocompletar durante algún tiempo y casi se volvió a su nueva aplicación de descarga de todas las palabras clave hasta que finalmente conseguí que funcione. Lo que hice fue;
//In the onCreate //The suggestArray is just a static array with a few keywords this.suggestAdapter = new ArrayAdapter<String>(this, this.suggestionsView, suggestArray); //The setNotifyOnChange informs all views attached to the adapter to update themselves //if the adapter is changed this.suggestAdapter.setNotifyOnChange(true);
En el método onTextChanged de mi textwatcher, obtengo el sugiere usar un asynctask
//suggestsThread is an AsyncTask object suggestsThread.cancel(true); suggestsThread = new WertAgentThread(); suggestsThread.execute(s.toString());
En el método onPostExecute de AsyncTask, actualizo la autocompletetextview
//suggestions is the result of the http request with the suggestions this.suggestAdapter = new ArrayAdapter<String>(this, R.layout.suggestions, suggestions); this.suggestions.setAdapter(this.suggestAdapter); //notifydatasetchanged forces the dropdown to be shown. this.suggestAdapter.notifyDataSetChanged();
Consulte setNotifyOnChange y notifyDataSetChanged para obtener más información
AutoCompleteTextView eT = (AutoCompleteTextView)findViewById(R.id.searchAutoCompleteTextView_feed); // eT.addTextChangedListener(this); String[] sa = new String[]{"apple", "mango", "banana", "apple mango", "mango banana"}; ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, sa); eT.setAdapter(aAdapter);
Su trabajo sólo comentario sobre et.addtext línea …
Esto es un fragmento de mi proyecto. Creo que después de obtener los datos de los servicios todo lo que tienes que hacer es:
- Borrar los datos anteriores.
- Borrar los valores del adaptador anterior.
- A continuación, agregue valores a su lista de datos mediante el método add () o addAll ().
-
Notifique los datos cambiados llamando a notifyDataSetChanged () en el adaptador.
@Override public void onGetPatient(List<PatientSearchModel> patientSearchModelList) { //here we got the raw data traverse it to get the filtered names data for the suggestions stringArrayListPatients.clear(); stringArrayAdapterPatient.clear(); for (PatientSearchModel patientSearchModel:patientSearchModelList){ if (patientSearchModel.getFullName()!=null){ stringArrayListPatients.add(patientSearchModel.getFullName()); } } //update the array adapter for patient search stringArrayAdapterPatient.addAll(stringArrayListPatients); stringArrayAdapterPatient.notifyDataSetChanged();
}
Pero antes de todo esto asegúrese de que ha conectado el adaptador a la auto texto completo si no lo hacen de la siguiente manera:
ArrayAdapter<String> stringArrayAdapterPatient= new ArrayAdapter<String>(getActivity(),android.support.v7.appcompat.R.layout.select_dialog_item_material,stringArrayListPatients); completeTextViewPatient.setAdapter(stringArrayAdapterPatient);
- Servidor para transmitir RTSP a android
- Aplicación Java Minimax para Android en un juego tic-tac-toe