My problem was that below this code and until the onCreateDialog method completed, I had several methods controlling the spinner.
The first element of this counter is to βselect nothing,β and in this selection of the element I simply deleted the contents of this edit text, for example:
@Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { if(pos == 0){ if(editText.length() != 0 ) editText.setText(""); }
And I did not know that when creating the counter, it raises the "onItemSelected" event, and because of this, the edittext was erased every time, even when I did not click on this spinner element.
> Therefore, I managed to overcome this with a simple Boolean. Every time the onCreateDialog method puts a boolean value in true, and then my onItemSelected just works when this bolean is false.
Like the code below:
@Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { if(firstGoingSpinner){ firstGoingSpinner = false; }else{ if(pos == 0){ if(editText.length() != 0 ) editText.setText(""); }else{ editText.setText(""+parent.getItemAtPosition(pos)); Editable etext = editText.getText(); Selection.setSelection(etext, editText.length()); } } }
I hope this helps someone in the future;)
TiagoM
source share