2011-06-24 88 views
0

我在我的主視圖中有兩個紡紗廠。我在這些紡紗廠有一個項目清單,我確實使用adapter.getItem(position),因爲我需要得到的價值(比如說value1value2)我想等待用戶在紡紗廠中選擇一個項目,然後當發生在任何時間,我想執行一些代碼。完成此任務的最有效方法是什麼?如果value1value2爲空,我應該檢查onItemSelected嗎?有什麼建議麼?等待這兩個紡紗廠選擇一個項目

回答

1

檢查空位聽起來不錯。

//inside onItemSelected() 
if (spinner1value != null && spinner2value != null) { 
    DoYourStuff(); 
} 
0

2在僞代碼,我會做這樣的事情:

spinner1Selected = false; 
spinner2Selected = false; 

Spinner1ItemSelected { 
    spinner1Selected = true; 
    if(spinner1Selected == true && spinner2Selected == true) doMyStuff(); 
} 

Spinner2ItemSelected { 
    spinner1Selected = true; 
    if(spinner1Selected == true && spinner2Selected == true) doMyStuff(); 
} 

doMyStuff(){ 
    doing my stuff... 

    spinner1Selected = false; 
    spinner2Selected = false; 
}