在我的应用程序中,我正在使用2个微调器。我在两个微调器上使用onitemselectedListener但在我的第二个微调器监听器中不起作用。 如果有人能建议我适当的解决方案.... 我的代码是......
public class Expense extends Activity {
Spinner datype,distance;
public void onCreate(Bundle b){
super.onCreate(b);
setContentView(R.layout.expense);
datype=(Spinner)findViewById(R.id.da_type);
distance=(Spinner)findViewById(R.id.da_distance);
List<String>data1=new ArrayList<String>();
data1.add("Local");
data1.add("Ex-Station Double Side");
data1.add("Ex-Station Single Side");
data1.add("Out-Station Double Side");
data1.add("Out-Station Single Side");
ArrayAdapter<String>adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,data1);
adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
datype.setAdapter(adapter);
datype.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
if(datype.getSelectedItem().toString().equals("Local")){
mainlayout.setVisibility(View.GONE);
}
else {
mainlayout.setVisibility(View.VISIBLE);
}
if(datype.getSelectedItem().toString().equals("Local")){
try{
Statement smt=mycon.connection().createStatement();
rs=smt.executeQuery("DCR_GETEXPENSE '"+PA_ID+"'");
while(rs.next()){
daAmt.setText(rs.getString("DA_L"));
}
}catch(Exception e){
e.printStackTrace();
}
}
else if(datype.getSelectedItem().toString().equals("Ex-Station Double Side")||datype.getSelectedItem().toString().equals("Ex-Station Single Side")){
try{
Statement smt=mycon.connection().createStatement();
rs=smt.executeQuery("DCR_GETEXPENSE '"+PA_ID+"'");
while(rs.next()){
daAmt.setText(rs.getString("DA_EX"));
}
}catch(Exception e){
e.printStackTrace();
}
}
else{
try{
Statement smt=mycon.connection().createStatement();
rs=smt.executeQuery("DCR_GETEXPENSE '"+PA_ID+"'");
while(rs.next()){
daAmt.setText(rs.getString("DA_NS"));
}
}catch(Exception e){
e.printStackTrace();
}
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
station=new ArrayList<String>();
try{
CallableStatement stmt=mycon.connection().prepareCall("DCRDOCTORGRID '"+PA_ID+"','','','','','','',''");
stmt.execute();
rs=stmt.getResultSet();
rs.close();//i'st table
stmt.getMoreResults();
rs=stmt.getResultSet();
rs.close();//2'nd table
stmt.getMoreResults();
rs=stmt.getResultSet();
while(rs.next()){
station.add(rs.getString("STATION_NAME"));
}
}catch(Exception e){
e.printStackTrace();
}
ArrayAdapter<String>adapter2=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,station);
adapter2.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
distance.setAdapter(adapter2);
distance.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
if(distance.getSelectedItem().toString().equals("Zero Kilometer")){
Toast.makeText(getApplicationContext(),"0000",Toast.LENGTH.Short).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
在第二个微调器中,当我从微调器中选择该值时,我的toast没有显示 请帮帮我