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

  • SEARCH
  • Home
  • 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 5840013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:40:32+00:00 2026-05-22T11:40:32+00:00

I have one spinner in which few values are there from strings.xml and I

  • 0

I have one spinner in which few values are there from strings.xml and I want to populate that spinner dynamically from edit text using onclick event of Button but somehow it’s not working and I am getting Force Close everytime. Any help will be appreciated.

package com.example.expense;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class Expense3 extends Activity {
    //private TextView t1;

    private Spinner spinner;
    private EditText Text;
    private ArrayAdapter<CharSequence> adapter;
    private Button addButton;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Text = (EditText)findViewById(R.id.widget4);
        addButton = (Button)findViewById(R.id.add_new);

        spinner = (Spinner) findViewById(R.id.hhj);

         adapter = ArrayAdapter.createFromResource(
                this, R.array.planets_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);





        this.addButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                addNewSpinnerItem();
         }

            });

        }

    protected void addNewSpinnerItem() {
        // TODO Auto-generated method stub
        CharSequence textHolder = "" + Text.getText().toString();
        adapter.add(textHolder);


    }
}

Logcat error:-

05-14 01:07:19.934: ERROR/AndroidRuntime(802): FATAL EXCEPTION: main
05-14 01:07:19.934: ERROR/AndroidRuntime(802): java.lang.UnsupportedOperationException
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at java.util.AbstractList.add(AbstractList.java:411)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at java.util.AbstractList.add(AbstractList.java:432)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at android.widget.ArrayAdapter.add(ArrayAdapter.java:178)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at com.example.expense.Expense3.addNewSpinnerItem(Expense3.java:50)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at com.example.expense.Expense3$1.onClick(Expense3.java:40)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at android.view.View.performClick(View.java:2408)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at android.view.View$PerformClick.run(View.java:8816)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at android.os.Handler.handleCallback(Handler.java:587)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at android.os.Looper.loop(Looper.java:123)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at java.lang.reflect.Method.invokeNative(Native Method)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at java.lang.reflect.Method.invoke(Method.java:521)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-14 01:07:19.934: ERROR/AndroidRuntime(802):     at dalvik.system.NativeStart.main(Native Method)
  • 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-05-22T11:40:33+00:00Added an answer on May 22, 2026 at 11:40 am

    You are trying to add item in the adapter which is created from resources so it will give you result unsupported. To solve this issue you can create a blank List and then add items in the List from your resources. For that you can use Arrays.asList() or you can make a loop and add individual items in the List and after creating a List you will have to create a adapter using that List.

    Now to add a item in the adapter of the spinner you can use the adapter.add() method to add a item inside the spinner adapter.
    Here is a example that explain how you can create a adapter and add item in the spinner.

    adapter = new ArrayAdapter<String>(this, 
    android.R.layout.simple_spinner_item, array);
    

    Here array is a List.

    And for add item in the spinner you can use the add method.

    adapter.add("String to insert into spinner");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented button which clicks and opens dialog with spinner inside as described
I have an Android application which retrieves from a external server, a name and
In my app, I have a Spinner , that can be filled with two
i have two spinner one is for country and the second one is for
two days ago i noticed something. I have a spinner over a map activity.
I'm trying to ajaxify my will_pagniate pagination in rails. I want to have the
Here's an interesting question that I'm shocked hasn't been asked more often on the
this may be a simple question but i was wondering, i have an application
Please excuse me if this is a very novice question, but I am little
I am using the jQuery UI with applied Theme to a datatables.net element. Unfortunately,

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.