This is the tutorial that I followed to use a custom Listview Adapter. The problem I am having is that when I try to clear the adapter, the app crashes and throws java.lang.UnsupportedOperationException
if(adapter != null) {
adapter.clear();
}
UPDATED CODE:
private void setListViewAdapterToDate(int month, int year, int dv)
{
if(summaryAdapter != null) {
summaryAdapter.clear();
}
setListView(month, year, dv);
summaryList.addAll(Arrays.asList(summary_data));
summaryAdapter = new SummaryAdapter(this.getActivity().getApplicationContext(), R.layout.listview_item_row, summaryList);
summaryAdapter.notifyDataSetChanged();
calendarSummary.setAdapter(summaryAdapter);
}
Looking around a bit, it would seem that initializing the adapter with an array is the problem. See UnsupportedOperationException with ArrayAdapter.remove and Unable to modify ArrayAdapter in ListView: UnsupportedOperationException
Try using an
ArrayListinstead of anarraylike soIf you’re feeling lazy, you can convert your
arrayto anArrayListthis wayTo finish the conversion to
ArrayListin yourWeatherAdapterclass you will want to remove theWeather data[] = null;and all of it’s references (such as inside the constructor) becauseArrayAdapterholds the data for you and you can access it with getItemSo inside of your
getViewfunction you would changeWeather weather = data[position];toWeather weather = getItem(position);Update
Modify your udated code with