我根据应用的某些规则创建了一个Spinner。所以,它是动态创建的。如何检索选择了哪个项目?
Spinner mySpinner = (Spinner)linearMoreInfo.getChildAt(1);
使用此代码检索创建的动态微调器。但不知道我如何处理其点击/选择项目。
有帮助吗?
答案 0 :(得分:4)
我希望它适合你:
mySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
{
Object obj = parent.getItemAtPosition(pos);
...
}
public void onNothingSelected(AdapterView<?> parent) { }
});
答案 1 :(得分:0)
试试此代码......
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int pos, long arg3) {
// TODO Auto-generated method stub
selected_item_position = pos;
selected_item = spinner.getSelectedItem().toString();
// You can insert your code...
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});