开发者

Check if there is no option selected on a ListPreference

开发者 https://www.devze.com 2023-04-03 01:30 出处:网络
I want to show a toast when the user did not selected an option from a ListPreference, for that i tried this code and did not work:

I want to show a toast when the user did not selected an option from a ListPreference, for that i tried this code and did not work:

SharedPrefer开发者_如何学编程ences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        final String carbu;
        carbu = prefs.getString("listPref_carbu", "0");

         if ((Integer.valueOf(carbu) != 0) && (Integer.valueOf(carbu) != 1) && (Integer.valueOf(carbu) != 2)) {
             Toast.makeText(Acceuil.this, "Veuillez paramétrer votre voiture depuis la section 'Paramètres'", Toast.LENGTH_SHORT).show();

Have you any idea of how solving this problem? Thank you.


Try changing this line:

carbu = prefs.getString("listPref_carbu", "0"); 

To:

carbu = prefs.getString("listPref_carbu", "-1");
0

精彩评论

暂无评论...
验证码 换一张
取 消