У меня проблема со счетчиком. Когда я автоматически открываю класс (где есть прядильщик), он выбирает меня последним элементом в списке, но не показывает мне сообщение в тосте. И когда я выбираю элемент, щелкая по нему, они появляются мне сообщение. Что не так в моем коде?
Вот мой код:
public class SelectCodIncidence extends Activity {
private ArrayList<String> datos;
protected netAppApplication app;
Spinner sp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.codigoincidencia);
datos = new ArrayList<String>();
//datosCod = new ArrayList<String>();
try {
NotesCenter messageCenter = new NotesCenterImpl();
List<CodIncidence> codincidence = messageCenter.getCodIncidence();
for (CodIncidence e : codincidence) {
//datosCod.add("1");
datos.add(e.id);
}
} catch (Exception ex) {
// showMessage(ex);
Log.v("blah", ex.getMessage());
}
sp = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> adaptador =
new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, datos);
sp.setAdapter(adaptador);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, android.view.View arg1, int arg2, long arg3) {
int count = sp.getCount();
if (count > 0){
sp.setSelection(count -1,true);
int item = sp.getSelectedItemPosition();
Toast.makeText(getBaseContext(),
"Incidence Selected: " + datos.get(item),
Toast.LENGTH_SHORT).show();
}
}
public void onNothingSelected(AdapterView<?> arg0) {
return;
}
});
}
}
}
LOG:
01-05 13: 58: 04.097: E / AndroidRuntime (1944): ИСКЛЮЧИТЕЛЬНОЕ ИСКЛЮЧЕНИЕ: основное
01-05 13: 58: 04.097: E / AndroidRuntime (1944): java.lang.StackOverflowError
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.text.Styled.measureText (Styled.java:430)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.text.Layout.measureText (Layout.java:1655)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.text.Layout.getLineMax (Layout.java:689)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.text.Layout.getLineWidth (Layout.java:671)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.TextView.compressText (TextView.java:5150)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.TextView.makeNewLayout (TextView.java:5129)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.TextView.onMeasure (TextView.java:5328)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.view.View.measure (View.java:8313)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.Spinner.setUpChild (Spinner.java:228)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.Spinner.makeAndAddView (Spinner.java:185)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.Spinner.layout (Spinner.java:151)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelectionInt (AbsSpinner.java:292)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelection (AbsSpinner.java:269)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): в Net.App.SelectCodIncidence $ 1.onItemSelected (SelectCodIncidence.java:64)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.fireOnSelected (AdapterView.java:871)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.selectionChanged (AdapterView.java:854)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.checkSelectionChanged (AdapterView.java:977)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.Spinner.layout (Spinner.java:161)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelectionInt (AbsSpinner.java:292)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelection (AbsSpinner.java:269)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): в Net.App.SelectCodIncidence $ 1.onItemSelected (SelectCodIncidence.java:64)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.fireOnSelected (AdapterView.java:871)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.selectionChanged (AdapterView.java:854)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.checkSelectionChanged (AdapterView.java:977)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.Spinner.layout (Spinner.java:161)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelectionInt (AbsSpinner.java:292)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelection (AbsSpinner.java:269)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): в Net.App.SelectCodIncidence $ 1.onItemSelected (SelectCodIncidence.java:64)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.fireOnSelected (AdapterView.java:871)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.selectionChanged (AdapterView.java:854)01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.checkSelectionChanged (AdapterView.java:977)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.Spinner.layout (Spinner.java:161)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelectionInt (AbsSpinner.java:292)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelection (AbsSpinner.java:269)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): в Net.App.SelectCodIncidence $ 1.onItemSelected (SelectCodIncidence.java:64)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.fireOnSelected (AdapterView.java:871)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.selectionChanged (AdapterView.java:854)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.checkSelectionChanged (AdapterView.java:977)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.Spinner.layout (Spinner.java:161)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelectionInt (AbsSpinner.java:292)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelection (AbsSpinner.java:269)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): в Net.App.SelectCodIncidence $ 1.onItemSelected (SelectCodIncidence.java:64)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.fireOnSelected (AdapterView.java:871)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.selectionChanged (AdapterView.java:854)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.checkSelectionChanged (AdapterView.java:977)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.Spinner.layout (Spinner.java:161)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelectionInt (AbsSpinner.java:292)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelection (AbsSpinner.java:269)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): в Net.App.SelectCodIncidence $ 1.onItemSelected (SelectCodIncidence.java:64) 01-05 13: 58: 04.097: E / AndroidRuntime (1944): в Android .widget.AdapterView.fireOnSelected (AdapterView.java:871)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.selectionChanged (AdapterView.java:854)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.checkSelectionChanged (AdapterView.java:977)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.Spinner.layout (Spinner.java:161)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelectionInt (AbsSpinner.java:292)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AbsSpinner.setSelection (AbsSpinner.java:269)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): в Net.App.SelectCodIncidence $ 1.onItemSelected (SelectCodIncidence.java:64)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.fireOnSelected (AdapterView.java:871)
01-05 13: 58: 04.097: E / AndroidRuntime (1944): на android.widget.AdapterView.selectionChanged (AdapterView.java:854)