如何从两个项目的微调器获取选定的值

时间:2013-02-07 05:36:31

标签: android spinner android-arrayadapter

如何从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);

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

1 个答案:

答案 0 :(得分: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);

    }