如何从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值
如果有人知道请帮助我
答案 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);
}