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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:45:16+00:00 2026-05-24T12:45:16+00:00

I have developed an application in which i have one edit text value of

  • 0

I have developed an application in which i have one edit text value of edit text is entered in spinner on button clicked an the item i select to delete gets deleted but the problem is that when i delete the last item of spinner whole spinner list flushes . i want to delete only selected item(only last item)

My code is as follows :

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

    ///////////////////////////////////////////////////////////////
    // grab our UI elements so we can manipulate them (in the case of the
    // Spinner)
    // or add listeners to them (in the case of the buttons)
    m_myDynamicSpinner = (Spinner) findViewById(R.id.dynamicSpinner);
    m_addItemText = (EditText) findViewById(R.id.newSpinnerItemText);
    Button addButton = (Button) findViewById(R.id.AddBtn);
    Button clearButton = (Button) findViewById(R.id.ClearBtn);

    // //////////////////////////////////////////////////////////////
    // create an arrayAdapter an assign it to the spinner
    m_adapterForSpinner = new ArrayAdapter(this,
            android.R.layout.simple_spinner_item);
    ((ArrayAdapter) m_adapterForSpinner)
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    m_myDynamicSpinner.setAdapter(m_adapterForSpinner);
    // m_adapterForSpinner.add("dummy item");

    // //////////////////////////////////////////////////////////////
    // add listener for addButton
    addButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            addNewSpinnerItem();
        }
    });

    clearButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            clearSpinnerItems();
        }
    });
}

// //////////////////////////////////////////////////////////////
// add listener for addButton
private void addNewSpinnerItem() {
    Log.v("TAG", "addNewSpinnerItems called");

    if (m_addItemText.getText().length() == 0) {// ||(m_addItemText.getText().toString()==
        // " ")){
        Log.v("In if cndtn", "textHolder is of length 0");
        Toast.makeText(getApplicationContext(), "The textView is empty",
                Toast.LENGTH_LONG).show();
        //m_myDynamicSpinner.clearFocus();
        //m_myDynamicSpinner.setFocusable(false);
        //m_addItemText.setFocusable(true);
    } else {
        CharSequence textHolder = "" + m_addItemText.getText();
        // else{
        Log.v("else", textHolder + "");
        // m_adapterForSpinner.add(textHolder);
        // }
        ((ArrayAdapter) m_adapterForSpinner).add(textHolder);
    }
    m_addItemText.setText("");
}

private void clearSpinnerItems() {
    // m_adapterForSpinner.clear();
    Log.v("TAG", "clearSpinnerItems called");
    m_myDynamicSpinner
            .setOnItemSelectedListener(new OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> parent,
                        View view, int pos, long id) {
                    // TODO Auto-generated method stub
                    Log.v("TAG", "Itemseleted to be removed is "
                            + m_adapterForSpinner.getItem(pos).toString());
                    Log.v("Position of item", pos + "");
                    Object t = m_adapterForSpinner.getItem(pos);
                    Log.v("Object t ", (String) t);

                    ((ArrayAdapter) m_adapterForSpinner).remove((CharSequence) t);
                    Log.v("Item removed", t + "");

                    // m_myDynamicSpinner.setSelected(false);
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                    // TODO Auto-generated method stub

                }
            });
    // m_adapterForSpinner.add("dummy item");
}
  • 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-24T12:45:16+00:00Added an answer on May 24, 2026 at 12:45 pm

    for delete all items use:

    mySpinner.setAdapter(null);
    

    if you want to delete a particular item, remove this from m_adapterForSpinner and then:

    mySpinner.setAdapter(m_adapterForSpinner);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed one application which used to send/receive mails using Exchange Server 2003
I have developed one application which can using hashset concept. I have to override
I have developed a Windows application which has one DataGrid. I am assigning Defaultview
I have developed the application in which i want to set the background color
I have developed a simple location aware iPhone application which is functionally working very
Hai I have developed a standalone application in which when an user logs in,
I am developing a web application which has Chart Controls. I have developed a
I am new to iPhone world. I have developed an application, which I would
I have developed a Win32 application using C/C++, which runs on Vista and XP.
I have an application which was developed under Windows, but for gcc. The code

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.