2013-02-09 64 views
0

我有一個包含一個微調框和一個提交按鈕的頁面。我想要實現的是,當用戶選擇列表中的一個項目並單擊提交時,應該將他帶到具有webview的其他佈局。微調器中的每個項目都應在佈局中打開不同的.html頁面。如何將不同的活動分配給微調器的每個項目?

我現在已經是該項目正在從微調選擇,但我不知道如何執行的onclick監聽器,它...爲主要活動

代碼是在這裏

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.beef); 


     addListenerOnButton(); 
     addListenerOnSpinnerItemSelection(); 

    } 


    public void addListenerOnSpinnerItemSelection(){ 

     spinner1 = (Spinner) findViewById(R.id.spinner1); 
     spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener()); 
    } 

    //get the selected dropdown list value 
    public void addListenerOnButton() { 

     spinner1 = (Spinner) findViewById(R.id.spinner1); 

     btnSubmit = (ImageButton) findViewById(R.id.imageButton1); 

     btnSubmit.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       /*Nothing as of now*/ 
       //I need to call the ID of the selected item from the spinner here and start new activity 
      } 

     }); 

    } 

} 
CustomOnItemSelectedListener的

代碼是在這裏

@Override 
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, 
      long arg3) { 
     // TODO Auto-generated method stub 
     if (arg2 == 0) // First item selected 
    { 
    //Here I need to give an id for the .html file 

    } 
    else if (arg2 == 1) // Second 
    { 
      //Here I need to give an id for the .html file 
    } 



    } 

    @Override 
    public void onNothingSelected(AdapterView<?> arg0) { 
     // TODO Auto-generated method stub 

    } 

回答

0
@Override 
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { 

    String selItem = arg0.get(arg2); // String representation of the selected item 

    if (arg2 == 0) // First item selected 
    { 

    } 
    else if (arg2 == 1) // Second 
    { 

    } 
    // etc 
} 

@Override 
public void onNothingSelected(AdapterView<?> arg0) { 
     // TODO Auto-generated method stub 
} 
相關問題