这是我的arrayValues(的一部分):
<string-array name="securityValues">
<item name="wep">"capabilities LIKE '%WEP%'"</item>
<item name="wpa">"capabilities LIKE '%WPA%'"</item>
<item name="free">"capabilities NOT LIKE '%WPA%' AND capabilities NOT LIKE '%WEP%' AND capabilities NOT LIKE '%WPS%'"</item>
<item name="all">"1"</item>
这是我的preferences.xml的一部分
<ListPreference
android:key="visualizzazione_marker_security"
android:title="Sicurezza Wifi da visualizzare"
android:summary="Scegli con quale protocollo di sicurezza vuoi che siano visualizzate le wifi"
android:entries="@array/security"
android:entryValues="@array/securityValues"
/>
最后是我的代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(Menu.NONE, 0, 0, "Only free wifi");
menu.add(Menu.NONE, 1, 1, "All wifi");
return super.onCreateOptionsMenu(menu);
}
switch (item.getItemId()) {
case 0:
Editor edit = PreferenceManager.getDefaultSharedPreferences(this).edit();
edit.putString("visualizzazione_marker_security","capabilities NOT LIKE \'%WPA%\' AND capabilities NOT LIKE \'%WEP%\' AND capabilities NOT LIKE \'%WPS%\'").apply();
edit.commit();
Toast.makeText(this, "Wait 30 seconds please", Toast.LENGTH_LONG).show();
case 1:
Editor edit1 = PreferenceManager.getDefaultSharedPreferences(this).edit();
edit1.putString("visualizzazione_marker_security","1").apply();
edit1.commit();
Toast.makeText(this, "Wait 30 seconds please", Toast.LENGTH_LONG).show();
return true;
}
为什么case0不应用修改?首选项中的值始终更改为 1!