これは私の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 に変わります!