jeudi 28 janvier 2016

AutoCompleteTextView Not Working Properly when adding data from Database

Hey I have AutoCompleteTextView which works fine when I define my string statically like this..

private String Names[] = {"Chuck Norris", "Mr T", "Donald Trump"};

and then I do this..

  ArrayAdapter<String> adapter = new ArrayAdapter<String>
            (this, android.R.layout.select_dialog_item, Names);
    //Getting the instance of AutoCompleteTextView

    catgNames.setThreshold(0);//will start working from 0 character
    catgNames.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView

But when I try to load some data from Sqlite, the dropdown suggestion doesn't work. I'm doing something like this..

  Categories = new String[100]
  int i =0;
  DatabaseHandler db = new DatabaseHandler(this);
    List<entries> entries1 = db.getCategories();
    for (entries cn : entries1) {
        Log.i("", cn.getCategories());

        Names[i] = cn.getCategories();
        i++;
    }

and after this I define the adapter..

    ArrayAdapter<String> adapter = new ArrayAdapter<String>
            (this, android.R.layout.select_dialog_item, Categories);
    //Getting the instance of AutoCompleteTextView

    catgNames.setThreshold(0);//will start working from 0 character
    catgNames.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView

This doesn't work.. There is no error or warning in logcat..

Aucun commentaire:

Enregistrer un commentaire