Android Spinner项目选定文本

时间:2012-03-14 15:01:34

标签: android

它看起来非常直接,但它对我不起作用。我正在尝试在选择项目时从Spinner获取项目文本。

sp = (Spinner) findViewById(R.id.stnacspinner);
        cspinner = aircraft.getDistinctStation();

       sp.setOnItemSelectedListener(new OnItemSelectedListener() {     
            @Override     
            public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) { 
                Functions.CustomToastShort(getBaseContext(),  sp.getSelectedItem().toString() );
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {

            }
        });

它返回“android.database.sqlite.Sq; LiteCursor @ 40e06dc0”

我做错了什么?

2 个答案:

答案 0 :(得分:0)

你得到的是对象的字符串表示形式,即内存地址。

sp = (Spinner) findViewById(R.id.stnacspinner); 
        cspinner = aircraft.getDistinctStation(); 

       sp.setOnItemSelectedListener(new OnItemSelectedListener() {      
            @Override      
            public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {  
                Functions.CustomToastShort(getBaseContext(),  sp.getSelectedItem().toString() );
            } 

            @Override 
            public void onNothingSelected(AdapterView<?> arg0) { 

            } 
        }); 

sp.getSelectedItem().toString() //returns "android.database.sqlite.Sq;LiteCursor@40e06dc0"

答案 1 :(得分:-1)

selectedItemView.getText()sp.getSelectedItem().getText()可以解决问题。