微调消息问题

时间:2012-01-05 12:54:39

标签: android spinner toast

我有旋转器的问题。当我自动打开课程(旋转器的位置)时,它会选择列表中的最后一项,但它不会在吐司中显示消息。当我通过点击选择项目时,它们会显示一条消息。我的代码有什么问题?

这是我的代码:

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):at Net.App.SelectCodIncidence $ 1.onItemSelected(SelectCodIncidence.java:64)01-05 13:58:04.097:E / AndroidRuntime(1944):at 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)

1 个答案:

答案 0 :(得分:1)

在这种情况发生后立即举起你的面包 如下所述

 if (count > 0){
    sp.setSelection(count-1,true);
     Toast.makeText(getBaseContext(), 
                "Incidence Selected: " + datos.get(item), 
                Toast.LENGTH_SHORT).show();