Deleting last item from spinner deletes the entire list?

The problem with your code is that the deletion is inside the onItemSelected callback, which gets called every time you are deleting an entry, thus deleting recursively until you effectively do not have any more entries to select. If you add a log inside that method: Log. D("Spinner", "Count: " + m_adapterForSpinner.getCount()) you will see what I mean.

I'm sure you can come up with more elegant code, but a quick and dirty hack is to set up a boolean flag to stop the recursion after the first deletion. See the snippet below and add the commented lines to your own code: public class SpinnerTest extends Activity { Spinner m_myDynamicSpinner; EditText m_addItemText; ArrayAdapter m_adapterForSpinner; public static boolean cleared = false; // parent, View view, int pos, long id) { Object t = m_adapterForSpinner. GetItem(pos); Log.

D("Spinner", "Count: " + m_adapterForSpinner.getCount()); if (!cleared) // D("Spinner", "Count: " + m_adapterForSpinner.getCount()); cleared=true; // I did it! } // code unchanged.

The problem with your code is that the deletion is inside the onItemSelected callback, which gets called every time you are deleting an entry, thus deleting recursively until you effectively do not have any more entries to select. If you add a log inside that method: Log. D("Spinner", "Count: " + m_adapterForSpinner.getCount()); you will see what I mean.

I'm sure you can come up with more elegant code, but a quick and dirty hack is to set up a boolean flag to stop the recursion after the first deletion. See the snippet below and add the commented lines to your own code: public class SpinnerTest extends Activity { Spinner m_myDynamicSpinner; EditText m_addItemText; ArrayAdapter m_adapterForSpinner; public static boolean cleared = false; // parent, View view, int pos, long id) { Object t = m_adapterForSpinner. GetItem(pos); Log.

D("Spinner", "Count: " + m_adapterForSpinner.getCount()); if (!cleared) // D("Spinner", "Count: " + m_adapterForSpinner.getCount()); cleared=true; // I did it! } // code unchanged.

1 this is right, after removing a item the Spinner select a new one and called himself until no item left. Xou shoud not register a onitemselect Listener but select the item you want to delete and delete it by clicking the Button – 2red13 May 24 at 8:24 @2red13 yes, that's what I would do also, but I am assuming this is a test case for a code I did not see, so I am giving the solution that changes the structure the least. In fact, this approach has a second problem: you cannot delete the option that is already selected (since it does not fire onItemSelected).

– Aleadam May 24 at 14:40 yes :) I got it your code worked for me thank you :) – iShrey May 25 at 12:44 @Shrey I'm glad it worked for you. Just make sure that the notice also the problem I mention in my comment to 2red13 above. – Aleadam May 25 at 14:08 yup.. I got it.. :) – iShrey May 25 at 16:03.

I cann't understand your question. Any way you can get the position of the selected item by using getSelectedItemPosition() method.

1 please see the code segment and tell me wat m doing wrong – Shruti May 11 at 7:39 m using android.R.layout. Simple_spinner_dropdown_item – Shruti May 11 at 7:42 and android.R.layout. Simple_spinner_item – Shruti May 11 at 7:42 @shruti...just try the following code in clearspinneritem m_myDynamicSpinner.

RemoveViewAt( m_myDynamicSpinner. GetSelectedItemPosition()); and put the listener code out of the method. – Kappi May 11 at 8:46 @jinda : I have tried your code but now profit for me – iShrey May 117 at 11:03.

M_myDynamicSpinner = (Spinner)findViewById(R.id. M_addItemText = (EditText)findViewById(R.id. Button addButton = (Button)findViewById(R.id.

Button clearButton = (Button)findViewById(R.id. M_adapterForSpinner = new ArrayAdapter(this, android.R.layout. MakeText(getApplicationContext(), "The textView is empty", Toast.

Public void onItemSelected(AdapterView.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions