2015-12-24 55 views
3

任何人都可以請解釋me實現微調的onNothingSelected()的利用實施例何時執行onNothingSelected方法?

public class SpinnerActivity extends Activity implements OnItemSelectedListener { 
    ... 

    public void onItemSelected(AdapterView<?> parent, View view, 
      int pos, long id) { 
     Toast.makeText(this,"Selected Item is -"+ (TextView)view.getText().toString(),Toast.LENGTH_SHORT); 
    } 

    public void onNothingSelected(AdapterView<?> parent) { 
     // Another interface callback 
Toast.makeText(this,"nothing is selected",Toast.LENGTH_SHORT); 
    } 
} 
+0

來自android文檔 「當選擇從該視圖中消失時要調用的回調方法。例如,當激活觸摸或適配器變空時,選擇可能會消失。 –

回答

1

onNothingSelected是當選擇從該視圖中消失時要調用的回調方法。例如,當觸摸被激活或者適配器變空時,選擇可以消失。 我認爲它幾乎可以解答你的問題。因此,如果您的微調器因爲其他原因消失,除了選擇該項目,那麼onNothingSelected將被調用。因此,它的名稱告訴它需要找出什麼時候沒有選擇

0

檢查這blog,好的解釋給出。 我希望這可以幫助。

+0

請用您自己的話分享博客中的重要細節 – Kirby