I want to make the ListPreference with key "map_mode" set the actual map mode in my MapActivity.java . So that when I click "Satellite" for instance in the Preferences screen, it changes on the Map.
I have a ListPreference setup like this settings.xml (preference.xml):
<PreferenceCategory
android:key="settings"
android:title="Settings" >
<CheckBoxPreference
android:defaultValue="true"
android:key="map_settings"
android:summary="Enable or Disable Map Settings"
android:title="Enable Map Settings" />
<ListPreference
android:defaultValue="Map"
android:dependency="map_settings"
android:entries="@array/mapMode"
android:entryValues="@array/mapModeValues"
android:key="map_mode"
android:summary="Change the display of the map"
android:title="Map Mode" />
</PreferenceCategory>
The "map_mode" is reading array values from this arrays.xml :
<string-array name="mapMode">
<item name="Map">Map</item>
<item name="Satellite">Satellite</item>
<item name="Traffic">Traffic</item>
</string-array>
<string-array name="mapModeValues">
<item name="Map">Map</item>
<item name="Satellite">Satellite</item>
<item name="Traffic">Traffic</item>
</string-array>
Thank you.
This is PreferenceScreen. When user presses one of these options I want it to update the MapActivity.
Have your MapActivity
call registerOnSharedPreferenceChangeListener()
, then process the SharedPreference
change in your OnSharedPreferenceChangeListener
.
Or, simply re-read and apply the preference in onResume()
, since your PreferenceActivity
and your MapActivity
will not be on the screen at the same time.
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.