1

如何从spinner..获取选定的项目名称?

这是我的代码

Spinner sp;
ArrayAdapter<String> adapter;
String numbers[] = { "AM", "PM"};

sp = (Spinner) findViewById(R.id.timing);
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, numbers);
sp.setAdapter(adapter);

我想从中获取 AM / PM 值,spinner 如果有人知道请帮助我

4

1 回答 1

4

采用OnItemSelectedListener

sp.setOnItemSelectedListener(this);

@Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3) 
    {
        String selected = arg0.getItemAtPosition(arg2).toString();
        System.out.println(selected);

    }
于 2013-02-07T05:38:16.250 回答