Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:10:52+00:00 2026-06-12T00:10:52+00:00

This is the tutorial that I followed to use a custom Listview Adapter. The

  • 0

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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:10:53+00:00Added an answer on June 12, 2026 at 12:10 am

    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 ArrayList instead of an array like so

    ArrayList<Weather> weather_data = new ArrayList<Weather>()
    weather_data.add( new Weather(R.drawable.weather_cloudy, "Cloudy") );
    // continue for the rest of your Weather items.
    

    If you’re feeling lazy, you can convert your array to an ArrayList this way

    ArrayList<Weather> weatherList = new ArrayList<Weather>();
    weatherList.addAll(Arrays.asList(weather_data));
    

    To finish the conversion to ArrayList in your WeatherAdapter class you will want to remove the Weather data[] = null; and all of it’s references (such as inside the constructor) because ArrayAdapter holds the data for you and you can access it with getItem

    So inside of your getView function you would change Weather weather = data[position]; to Weather weather = getItem(position);

    Update
    Modify your udated code with

    private void setListViewAdapterToDate(int month, int year, int dv)
    {
        setListView(month, year, dv); 
         if(summaryAdapter != null) {
            summaryAdapter.clear();
            summaryAdapter.addAll( summaryList );
            summaryAdapter.notifyDataSetChanged();
         } else {
             summaryList.addAll(Arrays.asList(summary_data));
             summaryAdapter = new SummaryAdapter(this.getActivity().getApplicationContext(), R.layout.listview_item_row, summaryList);
         }
        calendarSummary.setAdapter(summaryAdapter);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have followed this tutorial to use SQLite db in my android app. Since
I have followed this tutorial which allowed me to create a Silverlight DataGrid that
I followed along with this tutorial ( http://www.bit-101.com/blog/?p=1861 ) and noticed that upon saving
So I've used this tutorial to create a custom toast, that will display an
I want to use Google Maps in my application, I have followed this tutorial
I've followed this tutorial but when I try to run the application I get
I followed this tutorial to configure an application (generated by seam-gen) to use eclipselink
I have followed this tutorial about how to use the proximity alert and how
I am trying to use apn_on_rails and followed this tutorial to configure it The
I realize a service in Azure and to do that I followed this tutorial:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.