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 8015407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:15:05+00:00 2026-06-04T20:15:05+00:00

I have a following Spinner in the OnCreate Method: spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,

  • 0

I have a following Spinner in the OnCreate Method:

    spinnerArrayAdapter = new ArrayAdapter<String>(this,   android.R.layout.simple_spinner_item, accounts);
        spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view
        spinner.setAdapter(spinnerArrayAdapter); 
        spinner.setOnItemSelectedListener(this);

and I want add some entries to the Spinner in a other Method like this:

spinnerArrayAdapter.add(value.toString());
spinner.setAdapter(spinnerArrayAdapter); 

but the app crashes. What can I do?
Thanks!

  • 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-04T20:15:07+00:00Added an answer on June 4, 2026 at 8:15 pm

    You have 2 possibilities:

    Either:

    in place where you are about to add new record to adapter:
    spinnerArrayAdapter.add("Your new item");
    spinnerArrayAdapter.notifyDataSetChanged();

    Or:

    In your onCreate when initialising adapter add spinnerArrayAdapter.setNotifyOnChange(true);
    when you want to add record to adapter later simply call spinnerArrayAdapter.add("Your new item");. No need to call notifyDataSetChanged() as it has been called by add internally.

    in both cases you don’t have to re-assign adapter to spinner.

    if you initialize your adapter with array, add method will raise exception, as what adapter stores internally is (List<T>) Arrays.asList(objects) where objects is the array you provided in constructor. asList returns the List interface wrapper implementation over the array so it does not support add opeation. In order to be able to use adapter’s add method you must provide the backing data as List with supported add/remove methods – i suggest ArrayList.

    so in your case init it like that:

    spinnerArrayAdapter = new ArrayAdapter<String>(
            this, android.R.layout.simple_spinner_item, 
            new ArrayList<String>(Arrays.asList(accounts)));
    

    or longer but more efficent (e.g. you do not create
    overhead list object to be abandoned a moment later)

    final int length = accounts.length;
    ArrayList<String> backingData = new ArrayList<String>(length);
    for(int i=0; i<length; i++) {
        backingData.add(i, accounts[i]);
    }
    spinnerArrayAdapter = new ArrayAdapter<String>(
            this, android.R.layout.simple_spinner_item, backingData);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code populating a spinner, JSONObject jsonResponse = new JSONObject(new String(buffer));
I have made a Spinner in Android: category = (Spinner) findViewById(R.id.ev_category); category.setOnItemSelectedListener(new MyOnItemSelectedListener()); ArrayAdapter<CharSequence>
i have created following layout. <TableLayout android:layout_width=fill_parent android:layout_height=wrap_content android:orientation=horizontal > <TableRow> <TextView android:layout_width=fill_parent android:layout_height=wrap_content
Helo. I have the following requirement: I have a list (ListView or Spinner depends
I have following Html file with javascript. This gives me error that testCircle is
i want to use Android spinner with following data. Spinner will display only text
I have a delegate method with the following tasks: get something from the internet
I have this view controller with the following hierarchy: I am just trying to
I have the following code but I get an error on this line userSpinner.setAdapter(adapter);
I have been following the tutorial for adding spinner items to a spinner control

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.