Is there a way to change the displayed list inside of the Spinner after selection. I have 2 Strings, English and Finnish and I want to first change their language when one is selected, secondly change their order when the other is selected.
private void initLanguageSpinner() {
List<String> spinnerLocale = new ArrayList<>();
if ((currentdocumentLocale.toString().startsWith("deviceNameFi") || currentdocumentLocale.getLanguage().equals("fi"))) {
spinnerLocale.add(getLocalizedResources(context, currentdocumentLocale).getString(R.string.finnish_language));
spinnerLocale.add(getLocalizedResources(context, currentdocumentLocale).getString(R.string.english_language));
} else {
spinnerLocale.add(getLocalizedResources(context, currentdocumentLocale).getString(R.string.english_language));
spinnerLocale.add(getLocalizedResources(context, currentdocumentLocale).getString(R.string.finnish_language));
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), R.layout.document_spinner_item, spinnerLocale);
adapter.setDropDownViewResource(R.layout.document_spinner_dropdown_item);
customerSelectedLanguageSpinner.setAdapter(adapter);
customerSelectedLanguageSpinner.setSelection(0, false);
customerSelectedLanguageSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (customerSelectedLanguageSpinner.getSelectedItem().toString().equals(getLocalizedResources(context, currentdocumentLocale).getString(R.string.finnish_language))) {
onLocaleChangedFi();
initLanguageSpinner();
} else if (customerSelectedLanguageSpinner.getSelectedItem().toString().equals(getLocalizedResources(context, currentdocumentLocale).getString(R.string.english_language))) {
onLocaleChangedEng();
initLanguageSpinner();
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
By doing this it basically does what I need, but it also goes into an endless loop since the onItemSelected is always called after initialization, even when I do the .setSelection(0, false). Is there a way to do what I need?
EDIT
So I tried creating a new adapter and then notifying it of changes.
private ArrayAdapter<String> spinnerAdapter;
private void initLanguageSpinner() {
List<String> spinnerLocale = new ArrayList<>();
if ((currentdocumentLocale.toString().startsWith("deviceNameFi") || currentdocumentLocale.getLanguage().equals("fi"))) {
spinnerLocale.add(getLocalizedResources(context, currentdocumentLocale).getString(R.string.finnish_language));
spinnerLocale.add(getLocalizedResources(context, currentdocumentLocale).getString(R.string.english_language));
} else {
spinnerLocale.add(getLocalizedResources(context, currentdocumentLocale).getString(R.string.english_language));
spinnerLocale.add(getLocalizedResources(context, currentdocumentLocale).getString(R.string.finnish_language));
}
spinnerAdapter = new ArrayAdapter<>(getActivity(), R.layout.document_spinner_item, spinnerLocale);
spinnerAdapter.setDropDownViewResource(R.layout.document_spinner_dropdown_item);
customerSelectedLanguageSpinner.setAdapter(spinnerAdapter);
customerSelectedLanguageSpinner.setSelection(0, false);
customerSelectedLanguageSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (customerSelectedLanguageSpinner.getSelectedItem().toString().equals(getLocalizedResources(context, currentdocumentLocale).getString(R.string.finnish_language))) {
setSpinnerAdapter(customerSelectedLanguageSpinner.getSelectedItem().toString());
onLocaleChangedFi();
} else if (customerSelectedLanguageSpinner.getSelectedItem().toString().equals(getLocalizedResources(context, currentdocumentLocale).getString(R.string.english_language))) {
setSpinnerAdapter(customerSelectedLanguageSpinner.getSelectedItem().toString());
onLocaleChangedEng();
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
private void setSpinnerAdapter(String language){
if(language.equals("fi")){
String[] myListFinnish = new String[] { getLocalizedResources(context, currentdocumentLocale).getString(R.string.finnish_language), getLocalizedResources(context, currentdocumentLocale).getString(R.string.english_language)};
spinnerAdapter = new ArrayAdapter<>(getActivity(), R.layout.document_spinner_item, myListFinnish);
} else {
String[] myListEnglish = new String[] { getLocalizedResources(context, currentdocumentLocale).getString(R.string.english_language), getLocalizedResources(context, currentDocumentLocale).getString(R.string.finnish_language)};
spinnerAdapter = new ArrayAdapter<>(getActivity(), R.layout.document_spinner_item, myListEnglish);
}
spinnerAdapter.setDropDownViewResource(R.layout.document_spinner_dropdown_item);
spinnerAdapter.notifyDataSetChanged();
}
This way it does not even change the list strings or order. onLocaleChangedEng(); basically changes the Locale variable in the application.
your code is a dead loop. and if the adapter item data changed,
such as add, remove, clear by adapter you can use notifyDataSetChanged
method.
Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.
adapter.clear()/add(object)/addAll();
adapter.notifyDataSetChanged();
then the view will update but not init.
if the whole data changed, you can also recreate an adapter, and then set data
dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, newStringList);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerCategory.setAdapter(dataAdapter)
At the same time, you can also clear and addAll, then notifyDataSetChanged
adapter.clear() //remove all data;
adapter.addAll(source);
adapter.notifyDataSetChanged();
//or remove it, then insert it in the first. that is acturl for your conditon
adapter.remove(objcet) //remove special data;
adapter.insert(object,index);
adapter.notifyDataSetChanged();
Secondly, you can also set a Tag to make when init the onItemSelected not called. the code like this:
//define a tag when first it is 0
int check = 0;
//then in the onItemSelected add a check condition
public void onItemSelected(AdapterView<?> parent, View arg1, int pos,long id) {
if(++check> 1) {
//do some things when item selected.
}
}
use notifyDataSetChanged to update data, not every time init spinner. if you only want to remove the init selected effect, use the check tag.
Related
I am trying to update the spinner view by calling notifyDataSetChanged(). But its not updating.
The below is my Activity:
public class DisplayArchive2 extends AppCompatActivity {
List<String> yearslist;
Spinner spinner;
ArrayAdapter<String> dataAdapter;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.archive2);
spinner = (Spinner) findViewById(R.id.year_spinner);
yearslist = new ArrayList<String>();
yearslist.add("2017");
yearslist.add("2016");
yearslist.add("2015");
yearslist.add("2014");
yearslist.add("2013");
dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,yearslist);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
yearslist.clear();
yearslist.add("2010");
yearslist.add("2009");
yearslist.add("2008");
yearslist.add("2007");
yearslist.add("2006");
dataAdapter.notifyDataSetChanged();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
The list of years is not changing on selecting any year.
It looks like below
Try this use dataAdapter2.setNotifyOnChange(true); its working fine i have tested it my device
void setNotifyOnChange (boolean notifyOnChange)
Control whether methods that change the list (add(T), addAll(Collection), addAll(Object[]), insert(T, int), remove(T), clear(), sort(Comparator)) automatically call notifyDataSetChanged(). If set to false, caller must manually call notifyDataSetChanged() to have the changes reflected in the attached view. The default is true, and calling notifyDataSetChanged() resets the flag to true.
CODE
List<String> yearslist;
Spinner spinner;
ArrayAdapter<String> dataAdapter2;
spinner = (Spinner) findViewById(R.id.year_spinner);
yearslist = new ArrayList<String>();
yearslist.add("2017");
yearslist.add("2016");
yearslist.add("2015");
yearslist.add("2014");
yearslist.add("2013");
dataAdapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,yearslist);
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter2);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
} else {
yearslist.clear();
yearslist.add("2010");
yearslist.add("2009");
yearslist.add("2008");
yearslist.add("2007");
yearslist.add("2006");
dataAdapter2.setNotifyOnChange(true);
dataAdapter2.notifyDataSetChanged();
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
As per my understanding. You are notifying the adapter inside onItemSelected(). In case of Spinner adapter initialization onItemSelected() will get called once for first time . So the list you will get in Spinner is always the new one(i.e 2006-2010) never the first one(i.e 2013-2017).
So if you do notify adapter on some other action or maybe avoid the first call to onItemSelected() your code will work fine .
While there are many questions relating to this subject here on stackoverflow, I can say I've looked through many of them and tried different things, but still I don't get it to work.
I have a ListView which I populate with a custom Adapter of custom classes I've created. I also have a spinner, which I'm trying to use as a filter for the list.
This is my simplified code, I removed everything that isn't relevant here make it clearer as possible, also simplifying some of the variable names:
public class OnlineNavActivity extends AppCompatActivity {
private ListView tourList;
private ArrayList<Tour> toursData;
private Spinner filterSpinner;
private TourAdapter tourAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tours_online);
// Set up the spinner
filterSpinner = (Spinner) findViewById(R.id.country_spinner);
addItemsToSpinner();
filterSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selectedCountry = (String) parent.getItemAtPosition(position);
Log.i(LOG_TAG, selectedCountry);
if (!selectedCountry.equals(Data.ALL_COUNTRIES)) { // if string does not equal to "All Countries"
toursData = Data.listByFilter(selectedCountry);
}
else {
toursData = Data.dataList;
}
tourAdapter = new TourAdapter(getApplicationContext(), toursData);
tourAdapter.notifyDataSetChanged();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
toursData = Data.dataList;
tourAdapter = new TourAdapter(getApplicationContext(), toursData);
tourAdapter.notifyDataSetChanged();
}
});
// Assign all of the data to the array at first, will change by filter spinner
toursData = Data.dataList;
// Generate the list view
tourList = (ListView) findViewById(R.id.online_nav_list);
tourAdapter = new TourAdapter(this ,toursData);
tourList.setAdapter(tourAdapter);
}
(The Data.listByFilter() is the method I've created in a different class which returns an ArrayList with the applied filter).
The problem is that when I click on the spinner and select an item - nothing happenes.
I have tried to use tourAdapter.clear() and then adding the items with add command but that didn't work (The ListView became empty for any selection in the spinner).
Adding items to the adapter worked as items were added to the ListView and updated there, but this is not what I need, just something that worked while I was trying to figure this out.
Thanks.
Edit:
After trying many things, I finally find a solution. While it doesn't seem like an optimal solution, since I declare a new TourAdapter on every spinner action, this is the only one that worked for me.
What I did, is declaring a new TourAdapter and then calling setAdapter.
Also, I have left onNothingSelected as an empty method. This is what it looks like (all the other code remains the same):
filterSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selectedCountry = (String) parent.getItemAtPosition(position);
Log.i(LOG_TAG, selectedCountry);
if (!selectedCountry.equals(Data.ALL_COUNTRIES)) { // if string does not equal to "All Countries"
toursData = Data.listByFilter(selectedCountry);
Log.i(LOG_TAG, "first country is" + toursData.get(0).getCountry());
}
else {
toursData = Data.dataList;
}
tourAdapter = new TourAdapter(getApplicationContext() ,toursData);
tourList.setAdapter(tourAdapter);
//tourAdapter.notifyDataSetChanged();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
The problem is you are creating a new adapter (new TourAdapter(...) within onItemSelected and onNothingSelected methods) every time you click on the Spinner and this adapter is not linked to your list.
In this two methods, instead of creating a new one, you should get the adapter the list already has (you set it with tourList.setAdapter), create a method on the adapter that set the new elements on it and update the list with notifyDataSetChange.
String selectedCountry = (String) parent.getItemAtPosition(position);
Log.i(LOG_TAG, selectedCountry);
if (!selectedCountry.equals(Data.ALL_COUNTRIES)) {
toursData = Data.listByFilter(selectedCountry);
} else {
toursData = Data.dataList;
}
tourAdapter = ((TourAdapter) tourList.getAdapter()).setNewElements(toursData);
tourAdapter.notifyDataSetChanged();
The setNewElements should be a method in the adapter like this:
public void setNewElements(List<Tour> newElementsList) {
this.myElements = newElementsList;
}
***** Edit *****
String selectedCountry = (String) parent.getItemAtPosition(position);
Log.i(LOG_TAG, selectedCountry);
toursData.clear();
if (!selectedCountry.equals(Data.ALL_COUNTRIES)) {
toursData.addAll(Data.listByFilter(selectedCountry));
}
else {
toursData.addAll(Data.dataList);
}
tourAdapter.notifyDataSetChanged();
I have two spinners in an Activity where the second Spinner's selection set is based on what the user picked for the first Spinner. I use a private class variable in the Activity which is set in the top Spinner's OnItemSelectedListener and then referenced in the bottom Spinner's OnItemSelectedListener to obtain the correct selection set.
This almost always works, but sometimes (mainly when app was run, not exited, and then started again by a user click some long time later) I get a null pointer exception in the second Spinner's OnItemSelectedListener due to this local variable not being set. This indicates to me that after the OnCreate that the second Spinner's OnItemSelectedListener was called before the first Spinner's.
Is there any method to force a certain order in the listeners being fired or is there a better design approach to handle this second Spinner's dependency on the first Spinner?
Example code:
package com.crashtestdummylimited.navydecoder;
public class Test extends Activity {
// Variable that at times is still null
private ReferenceData referenceData;
private void setupSpinnerFromArray (int spinnerId, String stringArray[], OnItemSelectedListener listener) {
Spinner spinner = (Spinner) findViewById(spinnerId);
ArrayAdapter <CharSequence> adapter = new ArrayAdapter <CharSequence>(
this, android.R.layout.simple_spinner_item, stringArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(listener);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen);
// Setup Top (main) Spinner
Spinner spinner1 = (Spinner) findViewById(R.id.mainDecodeSpinner);
ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(
this, R.array.level0_list_array, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter1);
spinner1.setOnItemSelectedListener(new MainDecoderItemSelectedListener());
// Setup Bottom (dependent) Spinner
setupSpinnerFromArray(R.id.secondaryDecodeSpinner, R.array.level1_list_array, new SecondaryDecoderItemSelectedListener());
}
public class MainDecoderItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
String selectedString = parent.getItemAtPosition(pos).toString();
if (selectedString.equals("AAA")){
// Problem variable is set
referenceData = new RatingCodes();
setupSpinnerFromArray(R.id.secondaryDecodeSpinner, referenceData.getKeys(), new SecondaryDecoderItemSelectedListener());
}
else if (selectedString.equals("BBB")){
// Problem variable is set
referenceData = new IMSCodes();
setupSpinnerFromArray(R.id.secondaryDecodeSpinner, referenceData.getKeys(), new SecondaryDecoderItemSelectedListener());
}
// TODO: Improve what occurs if no match which should not occur
}
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing.
}
}
public class SecondaryDecoderItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
String key = parent.getItemAtPosition(pos).toString();
// **** referenceData being null at this point has caused crashed ****
String value = referenceData.getValue(key);
// ... Update text on activity screen ...
}
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing.
}
}
}
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id)
{
if(pos == 0)
{ //when it loads on onCreate() then pos is always 0
//donothing
}
else
{ //If user manually select item
//do what you need to do on manual user selection
}
}
I'm developing a Listview dynamically filled by a function that returns an ArrayAdapter which recieves a String parameter. This string parameter is the selected item of another dynamically filled Spinner.
When the function returns an ArrayAdapter with a number of items > 0, the Listview is sucessfully refreshed with the new items, but when the function returns 0 items on the ArrayAdapter, the listview doesn't clear the previous items. Here's the code I'm working on:
ManifiestoSpinner = (Spinner) findViewById(R.id.spnManifiesto);
FacturasListview = (ListView) findViewById(R.id.lvwFacturas);
ManifiestoSpinner = (Spinner)
ManifiestoSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String EstadoID = EstadoSpinner.getSelectedItem().toString();
ArrayList<String> ListManifiestos = (ArrayList<String>)Factura.GetManifiestosByEstado(EstadoID);
ActualizarManifiestSpinner(manifiesto);
}
public void onNothingSelected(AdapterView<?> arg0) {
}
private void ActualizarManifiestSpinner (ArrayList<String> manifiesto)
{
String[] datos = new String[manifiesto.size()];
ArrayAdapter<String> AdapterManifiesto = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item, manifiesto.toArray(datos));
ManifiestoSpinner.setAdapter(AdapterManifiesto);
}
ManifiestoSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String Manifiesto = ManifiestoSpinner.getSelectedItem().toString();
String Estado = EstadoSpinner.getSelectedItem().toString();
fillData(Estado, Manifiesto);
return;
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
private void fillData(String EstadoID, String ManifiestoID) {
ArrayAdapter<String> adapter = (ArrayAdapter<String>) FacturasListview.getAdapter();
if(adapter!= null)
{
adapter.clear();
FacturasListview.setAdapter(adapter);
FacturasListview.invalidateViews();
}
List<String> from = Factura.GetListClientesByEstadoManifiesto(EstadoID, ManifiestoID);
adapter = new ArrayAdapter<String>(this,R.layout.factura_row, R.id.text1 ,from);
FacturasListview.setAdapter(adapter);
}
When the List called from has from.size() = 0, the items previously show on the Listview are not cleared.
Thanks Nammari. I followed your recommendation but the FacturasListview doesn't have a method called notifyDatasetChanged(), the adapter does, so i got this code:
ArrayAdapter<String> adapter = (ArrayAdapter<String>) mFacturasListview.getAdapter();
if(adapter!= null)
{
adapter.clear();
adapter.notifyDataSetChanged();
}
Still the Listview won't refresh the items. I'm looking for a method that will clear all the items of a ListView that recieves an ArrayAdapter. I'm uploading two pictures to show what I'm working on.
"Imagen 1"
In this case, the first spinner has a selecteditem().toString() = "POR RECIBIR", and based on that parameter, the second spinner is dynamically filled with the codes of all the documents having (document.State = "POR RECIBIR"). After the second spinner is filled, a third method called "fillData" fills the ListView with all the Customer's name included on the document. This is the code:
private void fillData(String EstadoID, String ManifiestoID) {
ArrayAdapter<String> adapter = (ArrayAdapter<String>) mFacturasListview.getAdapter();
if(adapter!= null)
{
adapter.clear();
adapter.notifyDataSetChanged();
}
List<String> from = Factura.GetListClientesByEstadoManifiesto(EstadoID, ManifiestoID);
adapter = new ArrayAdapter<String>(this,R.layout.factura_row, R.id.text1 ,from);
FacturasListview.setAdapter(adapter);
}
The problem occurs when the first spinner has a selecteditem().toString() = "POR ENTREGAR", and based on that parameter, we find 0 documents having (document.State = "POR ENTREGAR"). Here, the third method called "fillData" should clear all ListView items, but it doesn't. This is the image:
"Imagen 2"
In your fillData method
if(adapter!= null)
{
adapter.clear();
FacturasListview.setAdapter(adapter);// !!!!!!!
FacturasListview.invalidateViews();
}
after calling adapter.clear(); setting the adapter of the ListView won't change anything
just call FacturasListview.notifyDatasetChanged();
like this
if(adapter!= null)
{
adapter.clear();
FacturasListview.notifyDatasetChanged();
}
this should clear all views in the list
in case you want to change the adapter of ListView i would make a custom array adapter with a method that takes the List and change the previous reference of the List in the adapter and after that call notifyDatasetChanged();
like this
class MyAdpater {
List<String> list;
.....
.....
public void setAdpaterList(List<String>list){
this.list= list;
}
}
then after calling this method call notifyDatasetChange() on your adapter
I wanted to display my data into android spinner from database.
I used two spinner..
2nd spinner should reflect once 1st spinner item is selected, every thing is working fine..data is loaded into the second spinner, but not displaying into 2nd spinner when 2nd spinner item is selected.
Spinner1 = (Spinner)findViewById(R.id.createProfileCitySpinnerId);
Spinner2 = (Spinner)findViewById(R.id.createProfileStateSpinnerId);
//for 1st spinner.....(working)
final List<String> list1 = new ArrayList<String>();
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,list1);
Spinner1.setAdapter(adapter1);
//for second spinner...
final List<String> list2 = new ArrayList<String>();
Spinner1.setOnItemSelectedListener(new OnItemSelectedListener(){
#Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
{
if(//some condition using id)
{
list2.add(stateCursor.getString(1));
}
}
#Override
public void onNothingSelected(AdapterView<?> parent)
{
}
});
//everything is working data is loading, but not display once item is selected on 2nd spinner
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,list2);
stateSpinner.setAdapter(adapter2);
You need to add the element directly to the adapter (not to list2), the ArrayAdapter keeps its own internal data. Try this code on your onItemSelected:
adapter2.add(stateCursor.getString(1));
adapter2.notifyDataSetChanged();
Call adapter2.notifyDataSetChanged();
such as
#Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
{
if(//some condition using id)
{
list2.add(stateCursor.getString(1));
adapter2.notifyDataSetChanged();
}
}
see http://developer.android.com/reference/android/widget/ArrayAdapter.html for more information.
public void notifyDataSetChanged () Since: API Level 1
Notifies the attached observers that the underlying data has been
changed and any View reflecting the data set should refresh itself.