I have a spinner in my Android app, and its onItemSelected()
event automatically gets triggered upon entering the activity.
How do I avoid this?
Simple and easy is this... validate with a boolean to see if is first time...
Spinner mySpinner = (Spinner)findViewById(R.id.spinner_xml_pro);
mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> adapterView, View view, int i, long l) {
if(isSpinnerInitial){ // globar var boolean isSpinnerInitial = false;
//do something
}else
isSpinnerInitial=true;
}
@Override
public void onNothingSelected(AdapterView> adapterView) {
}
});
Check this with spinner.post(new Runnable()...) or this other my source