这是实现 AdapterView.OnItemSelectedListener 的嵌套类。这提供了一个回调方法,当从 Spinner 中选择了一个项目时通知我的应用程序。但我不知道如何将 Selected String 值传递给主要活动?
public class CustomOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
String selected = parent.getItemAtPosition(pos).toString();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// Do nothing.
}
}
我像这样调用主要活动
public void addListenerOnSpinnerItemSelection() {
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
// I need the selected value here.........
}