Android Spinner Prompt Not Working
I have Spinners that I am using in my application. They are working fine with one exception. I have set prompts for each one, but they are not showing. I am setting ArrayAdapters t
Solution 1:
This seems to happen even if you put the OnItemSelectedListener in the onStart() method of the activity.
The work around I did for this issue was I put a default message in position 0 of my resource array ("Select Trip Type"). So when the OnItemSelectedListener is called, if position 0 is selected, then do nothing. Here is my code:
mTripTypeSpinner.setOnItemSelectedListener(newOnItemSelectedListener(){
@OverridepublicvoidonItemSelected(AdapterView<?> parent,View v,int position,long rowId) {
//boolean used for hiding spinnerbooleanhideSpinner=true;
switch(position){
case0:
//nothing was selected - defualt "Select Trip Type"
hideSpinner = false;
break;
case1:
mCurrentStop.setStopType(Stop.STOP_TYPE.DELIVERY);
break;
case2:
mCurrentStop.setStopType(Stop.STOP_TYPE.START_OF_BREAK);
break;
case3:
mCurrentStop.setStopType(Stop.STOP_TYPE.END_OF_BREAK);
break;
case4:
mCurrentStop.setStopType(Stop.STOP_TYPE.START_OF_LUNCH);
break;
case5:
mCurrentStop.setStopType(Stop.STOP_TYPE.END_OF_LUNCH);
break;
case6:
mCurrentStop.setStopType(Stop.STOP_TYPE.END_OF_TRIP);
break;
}
//display other data screens
displayData(hideSpinner);
}
@OverridepublicvoidonNothingSelected(AdapterView<?> arg0) {
mCurrentStop.setStopType(Stop.STOP_TYPE.DELIVERY);
}
});
Post a Comment for "Android Spinner Prompt Not Working"