2012-10-17 109 views
0

,當我再次是在適配器中的值不刷新,甚至onItemSelectedListener或NothingSelected不解僱onItemSelectedListener不會觸發

這裏selecteing相同的值如下我的代碼:

 spinner.setOnItemSelectedListener(new OnItemSelectedListener() { 
     public void onItemSelected(AdapterView<?> arg0, View arg1, 
       int arg2, long arg3) {     
       new MyBackgroundAsyncTask().execute(); 
     } 
     public void onNothingSelected(AdapterView<?> arg0) { 
       new MyBackgroundAsyncTask().execute(); 
     } 
    });  
+1

你不選擇,如果它已被選中,你是純粹的點擊。您可能需要爲這些情況設置點擊監聽器。 –

+0

好的。如何爲微調器設置點擊監聽器。當我嘗試toset監聽器時,它會得到一個異常,說不要創建setonclicklistener。 – lavan

+0

爲什麼你需要重新選擇一個選定的項目?你可以檢查當前選擇的項目,而不是如果這是你實際想要做的?我並不確定自己明白你想達到什麼目的。 –

回答

0
public class NoDefaultSpinner extends android.widget.Spinner { 

private static Method s_pSelectionChangedMethod = null; 

private int key = 0; 
static { 
    try {    
     Class noparams[] = {}; 
     Class targetClass = AdapterView.class; 
     s_pSelectionChangedMethod = targetClass.getDeclaredMethod("selectionChanged", noparams);    

     if (s_pSelectionChangedMethod != null) { 
      s_pSelectionChangedMethod.setAccessible(true);    
     } 

    } catch(Exception e) { 
     Log.e("Custom spinner, reflection bug:", e.getMessage()); 
     throw new RuntimeException(e); 
    } 
} 

public NoDefaultSpinner(Context context) {  
    super(context); 
} 

public NoDefaultSpinner(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public NoDefaultSpinner(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
} 

@Override 
public void onClick(DialogInterface dialog, int which) {  
    super.onClick(dialog, which); 
    // Here my code goes..... 

} 
+0

jus擴展微調類並覆蓋onclickListener。它會工作。 不要忘記在你的xml spinner聲明中提及。 – lavan