My Spinner is stuck, I can't seem to get it to retrieve the selected item. It is stuck on the first item of the string-array. I want the user to choose item then place markers on the map based on their selections. I don't want to predetermine the item and retrieve so I am using:
spinner.getSelectedItem().toString();
It should be simple and straight forward as that. Without having to code for each item in string-array. using .trim().equals(""). The biutton uses android:onClick and not setOnClickListener().
This is my code:
onMapReady() calls this method:
public void talktomap(){
//variables have been declared arleady
SP_course = (Spinner)findViewById(R.id.select_subject);
course= SP_course.getSelectedItem().toString();
//talk to map
if (loc=="Sydney" && level=="Form 3" && course=="Biology"){
map.addMarker(new MarkerOptions().position(MAU).title("Biology").snippet("You found us").alpha(0.7f).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
map.addMarker(new MarkerOptions().position(PortLoius1).title("Biology").snippet("..add your description here..").alpha(0.7f).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
map.addMarker(new MarkerOptions().position(new LatLng(-20.353, 57.65)).title("...").snippet("Biology Tutor Here").alpha(0.7f));
}else if (loc=="melbourne" && level=="Form 4" && course=="English"){
map.addMarker(new MarkerOptions().position(new LatLng(-20.2012, 57.6)).title("English").snippet("English Tutor Here").alpha(0.7f).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA)));
map.addMarker(new MarkerOptions().position(new LatLng(-20.2034, 57.6)).title("English").snippet("English Tutor Here").alpha(0.7f));
}else if (loc=="new york" && level=="Form 3" && course=="Chemistry"){
map.addMarker(new MarkerOptions().position(BonneTerre).title("Chemistry").snippet("Chemistry Tutor Here").alpha(0.7f).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA)));
map.addMarker(new MarkerOptions().position(BonneTerre1).title("Chemistry").snippet("Chemistry Tutor Here").alpha(0.7f).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA)));
}else {
Toast.makeText(this,"Sorry. No results found",Toast.LENGTH_LONG).show();
}
}
When the app starts it just displays the toast meaning it can enter the condition. When I choose different items and press the button the app crashes.
The string-array is stuck on 'Choose subject'
<string-array name="select_subject">
<item>-- Choose subject --</item>
<item>Biology</item>
<item>Chemistry</item>
<item>English</item>
<item>French</item>
<item>Mathematics</item>
</string-array>