I am fighting since many days with a same problem as I am new. I am retrieving an array list from an object like ArrayList of Trainee because I want all the data to be stored in Singleton class. For Autocomplete TextView I want the array of list to be used to show in dropdown of AutoComplete Text View. For that I need a String of data. And I know that, String toString() method is used to do so. But I have a problem because I used the Trainee class already to get an arrayList of Trainee. So when I try to use that method the previous arraylist uses it. May be the code explains more. The problem is that I cannot see the dropdown in my autocompleteText view. My activity class:
SearchTrainee = (AutoCompleteTextView) findViewById(R.id.search);
DatabaseHelper.getInstance();
suggestions = DatabaseHelper.getInstance().getTraineesList();
suggestionAdapter = new ArrayAdapter<Trainee>(this,
android.R.layout.simple_dropdown_item_1line, suggestions);
SearchTrainee.setAdapter(suggestionAdapter);
SearchTrainee.setThreshold(1);
My DatabaseHelper class to retrieve getTrainingList;
public void searchTrainee() {
this.setTraineesList(new ArrayList<Trainee>());
Cursor cursor = db.query(TABLE_PERSON,
new String[] { PERSON_ID, PERSON_FIRSTNAME, PERSON_LASTNAME,
PERSON_JOBTITLE, PERSON_EMAIL, PERSON_COMPANY,
PERSON_DEPARTMENT, PERSON_BADGE }, null, null, null,
null, null);
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
Log.i("HERE", "cursor moving...");
this.traineesList
.add(new Trainee(
Integer.parseInt(cursor.getString(cursor
.getColumnIndex(DatabaseHelper.PERSON_ID))),
cursor.getString(cursor
.getColumnIndex(DatabaseHelper.PERSON_FIRSTNAME)),
cursor.getString(cursor
.getColumnIndex(DatabaseHelper.PERSON_LASTNAME)),
cursor.getString(cursor
.getColumnIndex(DatabaseHelper.PERSON_JOBTITLE)),
cursor.getString(cursor
.getColumnIndex(DatabaseHelper.PERSON_EMAIL)),
cursor.getString(cursor
.getColumnIndex(DatabaseHelper.PERSON_COMPANY)),
cursor.getString(cursor
.getColumnIndex(DatabaseHelper.PERSON_DEPARTMENT)),
cursor.getString(cursor
.getColumnIndex(DatabaseHelper.PERSON_BADGE))));
}
} else {
this.traineesList.add(new Trainee(-1,
new String("Create New User"), new String(), new String(),
new String(), new String(), new String(), new String()));
}
}
public ArrayList<Trainee> getTraineesList() {
return traineesList;
}
public void setTraineesList(ArrayList<Trainee> traineesList) {
this.traineesList = traineesList;
}