3
我有一個活動,其中有多個紡紗器(約8-9)。我使用的代碼如下:OnItemSelectedListener多個紡紗器不能正常工作
Spinner sp1, sp2, sp3, sp4, sp5;
sp1 = (Spinner) findViewById(R.id.spinner1);
sp2 = (Spinner) findViewById(R.id.spinner2);
sp3 = (Spinner) findViewById(R.id.spinner3);
sp4 = (Spinner) findViewById(R.id.spinner4);
sp5 = (Spinner) findViewById(R.id.spinner5);
sp1.setOnItemSelectedListener(this);
sp2.setOnItemSelectedListener(this);
sp3.setOnItemSelectedListener(this);
sp4.setOnItemSelectedListener(this);
sp5.setOnItemSelectedListener(this);
//Outside onCreate I'm using the following to handle the spinner Item Selected event.
@override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
switch (arg0.getId()) {
case R.id.spinner1:
Toast.makeText(getApplicationContext(), arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_LONG).show();
break;
case R.id.spinner2:
Toast.makeText(getApplicationContext(), arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_LONG).show();
break;
case R.id.spinner3:
Toast.makeText(getApplicationContext(), arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_LONG).show();
break;
case R.id.spinner4:
Toast.makeText(getApplicationContext(), arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_LONG).show();
break;
case R.id.spinner5:
Toast.makeText(getApplicationContext(), arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_LONG).show();
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
但問題是,我沒有在任何紡織家選擇項目得到任何Toast
。任何幫助,將不勝感激。提前致謝。
即使這是不工作... –
@Tony斯塔克:你使我的天..工作就像一個魅力...很多很多感謝你... :) – AndroidLearner
@AndroidDeveloper什麼如果紡紗廠的數量超過了數百個,並且您不知道它們的確切數量,那麼請如何實施選擇方法回覆。 –