2012-10-18 37 views
0

我在EditText中獲得默認值,即使我沒有選擇從微調尚未。任何人都可以幫我嗎?Android:錯誤的onItemSelected爲微調

public void onItemSelected(AdapterView<?> parent, View v, int position, 
     long id) { 
    // TODO Auto-generated method stub 
    etCountry.setText(""); 
    switch(parent.getId()){ 
    case R.id.spcountry: 
     etCountry.setText(parent.getItemAtPosition(position).toString()); 
     break; 
    } 

} 
public void onNothingSelected(AdapterView<?> arg0) { 
    // TODO Auto-generated method stub 
    etCountry.setText(""); 
} 
+0

下面是一些很好的答案: http://stackoverflow.com/questions/4726490/android-set-spinner-default-value-to-null –

+0

你正在嘗試與開關盒呢? – gowri

+0

實際上我總共有4個Spinner.That y我正在使用switch&some us if/else。 –

回答

0

在你的代碼

您設置的EditText值清空etCountry.setText("");這裏。但是你在Switch case中再次設置該值。

開關罩

case R.id.spcountry: 
    etCountry.setText(parent.getItemAtPosition(position).toString());//Here is where you setting the edittext value again 
    //Do you stuff here if you dont want default text 
    break; 

編輯

地查找設置etCountry值。去Find-> or Press Ctl+F。輸入etCountry搜索它,你會發現你在哪裏設置值。

希望它能通過。

+0

我已經刪除了etCountry.setText(「」),但我仍然得到了Spinner的第一個值。 –

+0

然後我想一些你設置etCountry值的地方。你有沒有設置任何值在xml – GoCrazy

+0

更新的答案檢查它 – GoCrazy

相關問題