0

Consider the following combo list

comboList = new Spinner(this);
list_arr = new ArrayList<String>();

The ArrayList is filled with Strings from SharedPreferences and the Spinner is populated in this way

ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
        android.R.layout.simple_spinner_item, list_arr);
comboList.setAdapter(dataAdapter);

Then it gets updated in case of an event OnClickListener()

                list_arr.clear();
                ArrayList<String> res = getMyLists();
                for (int i = 0; i < res.size(); i++) {
                    list_arr.add(res.get(i));
                }

How can I refresh also the already selected item programmatically? From the GUI, I have to manually select another value from the list and then change it back.

This could be a duplicate of this other question but it is very old and unanswered.

Community
  • 1
  • 1
  • When you say you want to refresh the already selected item, do you mean that you would like it to be empty? or just set to the first item in the new list? – Coova Mar 12 '15 at 20:42
  • Set to the first item in the new list. I'm trying your answer. I will let you know, thanks for your help –  Mar 12 '15 at 20:46

2 Answers2

0

You may have to call dataAdapter.notifyDataSetChanged();

Coova
  • 1,818
  • 5
  • 36
  • 63
0

In this case, you'll need to re-create the spinner's adapter:

list_arr.clear();

ArrayList<String> res = getMyLists();
for (int i = 0; i < res.size(); i++) {
 list_arr.add(res.get(i));
}

dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list_arr);
comboList.setAdapter(dataAdapter);
mmark
  • 1,204
  • 12
  • 19