我有 8 个微调器:
pl1sp = (Spinner) offersdialoglayout.findViewById(R.id.pl1offer);
pl2sp = (Spinner) offersdialoglayout.findViewById(R.id.pl2offer);
pl3sp = (Spinner) offersdialoglayout.findViewById(R.id.pl3offer);
pl4sp = (Spinner) offersdialoglayout.findViewById(R.id.pl4offer);
和
pl1scores = (Spinner) scoresdialoglayout.findViewById(R.id.pl1scores);
pl2scores = (Spinner) scoresdialoglayout.findViewById(R.id.pl2scores);
pl3scores = (Spinner) scoresdialoglayout.findViewById(R.id.pl3scores);
pl4scores = (Spinner) scoresdialoglayout.findViewById(R.id.pl4scores);
我需要为他们设置 2 个听众。一个用于前 4 个微调器,一个用于最后 4 个。我不想重复这样的代码:
pl1sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
checkOffersSum(); // same method for first 4 spinners. for last 4 spinners is checkScoresSum()
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub.
}
});
pl2sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
checkOffersSum();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub.
}
});
等等..所以我只需要写两次监听器,第一次是前 4 个微调器,第二个是最后 4 个微调器。谢谢