AutoCompleteTextView dropdown list never appear

Put your problem here if it does not fit any of the other categories.

AutoCompleteTextView dropdown list never appear

Postby S___R » Mon Jan 30, 2012 3:10 pm

Hello all,

i have a little trouble in making my AutoCOmpleteTextView working correctly, i follow the code snipets that have been posted on this forum some month ago that you can found on this page : code-snippets-for-android-f33/autocompletetextview-cursoradapter-t12430.html

i have no error, the code is compiling correctly, and when i wrote something in the AutoCompleteTextView, i can see appearing in the LogCat window log from the "runQueryBackGroundThread" and from the "convertToString" methods, but never from "bindView" and "newView" ...
and the dropdown list never appear. i am sure that my query is working good, and the cursor is populated correctly, that's part of the information i have logged on.

maybe i missed something in my code that i dont have seen

i give the code of the CursorAdapter class :

Code: Select all
public class CustomAutoCompleteCursorAdapter extends CursorAdapter implements Filterable {
//public class CustomAutoCompleteCursorAdapter extends CursorAdapter {



   public CustomAutoCompleteCursorAdapter(Context context, Cursor c) {
      super(context, c);
      Log.i("NS", "j'initialise mon CursorAdapter");
   }

   @Override
   public void bindView(View view, Context context, Cursor cursor) {
      Log.i("NS", "debut du 'bindView'");
      if (cursor != null){
         ((TextView) view).setText( cursor.getString( cursor.getColumnIndex("codePostal") ) + " " + cursor.getString( cursor.getColumnIndex("libelleCommune") ) );
         cursor.close();
      }
      Log.i("NS", "fin du 'bindView'");
   }

   @Override
   public String convertToString(Cursor cursor) {
      // TODO Auto-generated method stub
      Log.i("NS", "debut du 'convertToString'");
      String retour = "";
      if (cursor != null){
         Log.i("NS", "taille du cursor : " + cursor.getCount());
         retour = cursor.getString( cursor.getColumnIndex("codePostal") ) + " " + cursor.getString( cursor.getColumnIndex("libelleCommune") );
         cursor.close();
      }
      Log.i("NS", "valeur de retour : " + retour);
      
      if (cursor != null){
         
         String[] listeColumn = cursor.getColumnNames();
         if (listeColumn != null){
            String colonne = "";
            for(int i = 0; i < listeColumn.length; i++){
               if (!"".equals(colonne)){
                  colonne += ";";
               }
               colonne += listeColumn[i];
            }
            Log.i("NS", "liste des colonnes du cursor de 'convertToString' : " + colonne);
         }
      }
      
      Log.i("NS", "fin du 'convertToStrings'");
      return retour;
      //return super.convertToString(cursor);
   }

   @Override
   public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
      // TODO Auto-generated method stub
      Log.i("NS", "debut du 'runQueryOnBackgroundThread'");
      Cursor retour = null;
      String mot = "-----";
      
      if (constraint != null){
         mot = constraint.toString();
      }
      
      ControleCommune ctrlC = new ControleCommune();
      retour = ctrlC.getSuggestionAutoCompletionCommune( mot );
      ctrlC.closeDB();//
      
      if (retour != null){
         Log.i("NS", "nombre de commune trouvées : " + retour.getCount());
         //retour.close();
      }else{
         Log.i("NS", "il n'y a aucune commune trouvées");
      }
      
      Log.i("NS", "fin du 'runQueryOnBackgroundThread'");
      return retour;
      //return super.runQueryOnBackgroundThread(constraint);
   }

   @Override
   public View newView(Context context, Cursor cursor, ViewGroup parent) {
      Log.i("NS", "debut du 'newView'");
      final LayoutInflater inflater = LayoutInflater.from( context );
      final TextView view = (TextView) inflater.inflate(android.R.layout.simple_dropdown_item_1line, parent, false);
      
      if (cursor != null){
         
         String[] listeColumn = cursor.getColumnNames();
         if (listeColumn != null){
            String colonne = "";
            for(int i = 0; i < listeColumn.length; i++){
               if (!"".equals(colonne)){
                  colonne += ";";
               }
               colonne += listeColumn[i];
            }
            Log.i("NS", "liste des colonnes du cursor de 'newView' : " + colonne);
         }
         
         view.setText( cursor.getString( cursor.getColumnIndex("codePostal") ) + " " + cursor.getString( cursor.getColumnIndex("libelleCommune") ) );
         cursor.close();
      }
      Log.i("NS", "fin du 'newView'");
      return view;
   }

}


and is implementation :

Code: Select all
this.localisation = (AutoCompleteTextView) findViewById( R.id.recherche_annonce_localisation );
ControleCommune ctrlC = new ControleCommune();
      
Cursor suggestion = ctrlC.getSuggestionAutoCompletionCommune("-----");
//CustomAutoCompleteCursorAdapter adapter = new CustomAutoCompleteCursorAdapter(getBaseContext(), suggestion);
CustomAutoCompleteCursorAdapter adapter = new CustomAutoCompleteCursorAdapter(this, suggestion);
this.localisation.setAdapter( adapter );
ctrlC.closeDB();


ok i didnt have clean this code, and some is only for test ....
sorry for my bad english, i am french, i hope every body can understand me after all ;)
S___R
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Jan 30, 2012 2:09 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 20 guests