3

I want to create a ListPreference in my settings that is populated with the different "years" that are stored in my SQLite database. I've gotten it to add all the years, however it adds them more than once if there is more than one of them. I cannot figure out how to make each appear only once (ex. 2012,2011,2010. instead of 2012,2012,2012,2011,2010,2010). Heres my code:

ListPreference listPreferenceCategory = (ListPreference) findPreference("Filter");

    entries = new ArrayList<String>();
    values = new ArrayList<String>();     

    mySQLiteAdapter = new SQLiteAdapter(this);

    mySQLiteAdapter.openToWrite();

    cursor = mySQLiteAdapter.queueAll6();
    cursor.moveToFirst();

    for(int i = 0; i < cursor.getCount();i++)
    {

        String year = cursor.getString(cursor.getColumnIndex(SQLiteAdapter.YEAR));

    if(Arrays.asList(entries).contains(year) == false){

        entries.add(year);

        values.add(year);
    }

    cursor.moveToNext();

    }


    final CharSequence[] charSequenceItems = entries.toArray(new CharSequence[entries.size()]);
    final CharSequence[] charSequenceItems2 = values.toArray(new CharSequence[values.size()]);

        listPreferenceCategory.setEntries(charSequenceItems);
        listPreferenceCategory.setEntryValues(charSequenceItems2);


    mySQLiteAdapter.close();

1 Answers1

2

figured it out. I needed to use String[] array = entries.toArray(new String[entries.size()]); and then Arrays.asList(array).contains(year) == false