Notifydatasetchanged() Not Updating My Array For My Spinner
QUESTION: If I set a variable prior to the onCreate can I use notifyDataSetChanged() to update an adapter that uses that array later? I am instigating my city_values array prior to
Solution 1:
It would be better to declare an ArrayList and then add the content in ArrayList and set the data to the adapter and notify.
publicclassSearchActivityextendsActivity{
ArrayAdapter<String> adapter2;
ArrayList<String> city_values = newArrayList<String>();
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_layout)
city_values.add("your content");
adapter2 = newArrayAdapter<String> (this,android.R.layout.simple_spinner_item, city_values);
adapter2.setDropDownViewResource(R.layout.city_spinner_layout);
cityspinner.setAdapter(adapter2);
Now if you want to update another spinner on this cityspinner selected item, you can take another ArrayList in the same way and add the items in that and set the Adapter.
UPDATE
Take an ArrayList<String> city_spinner_array = new ArrayList<String>;
for (int i=0; i<jsonArray.length(); i++)
{
String styleValue = jsonArray.getJSONArray(i).getString(0);
Log.d(TAG, styleValue);
city_spinner_array.add(styleValue);
}
And, now you will have your new values in city_spinner_array
. So, set the adapter and you did for the previous spinner.
Post a Comment for "Notifydatasetchanged() Not Updating My Array For My Spinner"