我需要为三个微调器编写一个监听器,只需创建一个监听器
请帮我解决下面给出的代码中的问题
public class MyActivity extends ActionBarActivity
{
Spinner MainSpinner,spinner1,spinner2;
EditText Edittext;
TextView TV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
Edittext = (EditText) findViewById(R.id.et1);
spinner1 = (Spinner) findViewById(R.id.spin1);
spinner2 = (Spinner) findViewById(R.id.spin2);
final TextView ta = (TextView)findViewById(R.id.et2);
MainSpinner = (Spinner) findViewById(R.id.MainSpin);
ArrayAdapter<CharSequence> MainspinAdapter = ArrayAdapter.createFromResource
(this, R.array.MainSpin, android.R.layout.simple_spinner_item);
MainspinAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
MainSpinner.setAdapter(MainspinAdapter);
final ArrayAdapter<CharSequence> TempAdapter = ArrayAdapter.createFromResource
(this, R.array.Temperature, android.R.layout.simple_spinner_item);
final ArrayAdapter<CharSequence> LengthAdapter = ArrayAdapter.createFromResource
(this, R.array.Length, android.R.layout.simple_spinner_item);
final ArrayAdapter<CharSequence> DigitalAdapter = ArrayAdapter.createFromResource
(this, R.array.Digital, android.R.layout.simple_spinner_item);
}
举一些例子来获取逻辑
答案 0 :(得分:2)
您可以在Activity中实现OnItemSelectedListener
,并在代码中使用覆盖方法:
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Spinner spinner = (Spinner) parent;
if(spinner.getId() == R.id.spinner1)
{
//do this
}
else if(spinner.getId() == R.id.spinner2)
{
//do this
}
}