I want to use a Option Menu for the user use switch the Map Type. hear code like i already use.
strings.xml
<string-array name="map_name"> <item>Normal</item> <item>Hybrid</item> <item>Satellite</item> <item>Straßenkarte</item> </string-array> <string-array name="map_string"> <item>"MAP_TYPE_NORMAL"</item> <item>"MAP_TYPE_HYBRID"</item> <item>"MAP_TYPE_SATELLITE"</item> <item>"MAP_TYPE_ROADMAP "</item> </string-array>
Einstellungen.java
public class Einstellungen extends PreferenceActivity implements Preference.OnPreferenceChangeListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); Preference map_string = findPreference(getString(R.array.map_string)); map_string.setOnPreferenceChangeListener(this); } @Override public boolean onPreferenceChange(Preference preference, Object value) { return false; } }
And now here i need some hind:
MapsActivity.java
public void onMapReady(final GoogleMap googleMap) { String mst = getResources().getString(R.array.map_string); googleMap.setMyLocationEnabled(true); googleMap.setMapType(GoogleMap.mst);
I think i have a big think error in my head. Can someone please give me a hind.
First off, won't
String mst = getResources().getString(R.array.map_string);
cause problems. Your trying to getString() on a string-array and pass it to a string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.