delete the particular selected item from the list of spinner

Put your problem here if it does not fit any of the other categories.

delete the particular selected item from the list of spinner

Postby ezhil » Mon Jan 24, 2011 5:55 am

hi,,,

I followed http://www.designerandroid.com/?p=8 this one to add the values in the spinner.In it while we select the "clear spinner items" the whole events are will be delete. But i need to the selected particular item only want to delete.Any one can help me.. The sample code will help to me lot.

Thank you.
ezhil
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 11, 2011 7:46 am

Top

Re: delete the particular selected item from the list of spi

Postby ezhil » Fri Feb 11, 2011 11:48 am

Hi friends i did that this is the answer:
Code: Select all

package com.samp.org;

   import android.app.Activity;
   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 samp extends Activity {
      
      private Spinner m_myDynamicSpinner;
      private EditText m_addItemText;
      private ArrayAdapter<CharSequence> m_adapterForSpinner;
      
       /** Called when the activity is first created. */
       @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<CharSequence>(this, android.R.layout.simple_spinner_item);
           m_adapterForSpinner.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);       
           m_myDynamicSpinner.setAdapter(m_adapterForSpinner);
           m_adapterForSpinner.add("Events:");       
          
           ////////////////////////////////////////////////////////////////
           //add listener for addButton
           addButton.setOnClickListener(new OnClickListener(){

            
            public void onClick(View v) {            
               addNewSpinnerItem();
            }                
           });
          
           ////////////////////////////////////////////////////////////////
           //add listener for addButton
           clearButton.setOnClickListener(new OnClickListener(){

            public void onClick(View v) {
               clearSpinnerItems();
            }          
           }); 
       }
      
       private void addNewSpinnerItem() {
          CharSequence textHolder = "" + m_addItemText.getText();
          m_adapterForSpinner.add(textHolder);
       }
      
      private void clearSpinnerItems() {
         m_adapterForSpinner.clear();
         m_adapterForSpinner.add("Events:");
      }      
   }
ezhil
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 11, 2011 7:46 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 36 guests