I am Using hashsetList to create a new list for my spinner without duplicates but java gives errors when I add this within the Spinner. Ithe project works fine when duplicates are shown from mySQL.
Here is the extract of MainActivity.java before I created the hashsetList.
@Override
protected void onPostExecute(Void args) {
// Locate spinner1 in activity_main.xml
Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
// Spinner adapter
spinner1.setAdapter(new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_spinner_dropdown_item,typesofjobs));
Collections.sort(typesofjobs);
When I added the following hashsetList code to eliminate duplicates and run it, the project crashes.
@Override
protected void onPostExecute(Void args) {
// Locate spinner1 in activity_main.xml
Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
Set<String> hashsetList = new HashSet<String>(typesofjobs);
// Spinner adapter
spinner1.setAdapter(new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_spinner_dropdown_item, (List<String>) hashsetList));
Collections.sort(typesofjobs);
Am I putting hashsetList in the wrong place or using it incorrectly? I am just trying to replace "typesofjobs" with the non duplicate version. Is there a better way I could eliminate my spinner duplicates?