int numberofSpinner = TransportResult.Transfers.size();
Spinner spin=null;
for(int i=0;i<numberofSpinner;i++)
{
spin = new Spinner(this);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,1);
spinLayout.addView(spin,p);
spin.setId(i);
Transfer transfer = TransportResult.Transfers.get(i);
ArrayList<CharSequence> s = new ArrayList<CharSequence>();
for( Line l : transfer.TransferLine)
{
s.add(l.ShortName+" - "+Helper.FindTransportTypeText(l.LineType));
}
adapter = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_spinner_item,s);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(adapter);
}
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
if(parent.getId()==0){
System.out.println("spin 1 is called");
String str = (String)parent.getSelectedItem();
}else if(parent.getId()==1){
System.out.println("spin 2 is called");
String str = (String)parent.getSelectedItem();
}
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
如果微调器的数量大于 1,则仅触发最后一个微调器。例如; 我在屏幕上有 3 个微调器,当我选择第一个或第二个微调器的项目时,永远不会触发侦听器。只有第三个微调器会触发侦听器。我该如何解决?
谢谢