0

当我再次选择适配器中的相同值时,值不会刷新,甚至不会触发 onItemSelectedListener 或 NothingSelected

下面是我的代码:

      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();
        }
    });     
4

1 回答 1

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.....

}
于 2012-11-08T11:00:42.063 回答