Update Spinner items at runtime

Asked

Viewed 298 times

1

I have a spinner that returns the saved cities in my comic book, when this city does not exist, I allow to register the same, and after registering and saving, I make to close the city registration Activity and return to the previous one that would be Activity containing the spinner, Only this city that just got saved doesn’t show up on my spinner, I have to get out of the app and back in it again so I can update that information. How do I update the spinner data at runtime, that is how I return to Activity that contains the spinner? Follow in my spinner:

List<String> labels = ds.getAllLabels();

spin = (Spinner) findViewById(R.id.spinner);

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

dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(dataAdapter);
  • Have you tried notifyDataSetChanged?

  • Already yes, but I could not implement in my project, would have some example?

  • Try to implement onActivityResult, in it put the method that redoes the search of cities and notifyDataSetChanged in Adapter.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.