Most probably your Int_Value doesn't exist. In this case the number you
specified, 200, will be assigned instead.

Thanks

On Sat, Aug 13, 2011 at 12:52 PM, Kristoffer <kris.isak.v...@gmail.com>wrote:

> Hello.
>
> Iam using shared preferences to store some values.
>
> final SharedPreferences pref = getSharedPreferences("MyPref",
> MODE_PRIVATE);
>
> final SharedPreferences.Editor edit = pref.edit();
>
> edit.putInt("Int_value", 1);
> edit.putString("String_Value", "test string");
> edit.commit();
>
>
> i look in the xml file and everything is saves as it should.
>
> now i grabb the values:
>
> int i = pref.getInt("Int_Value", 200);
> String s = pref.getString("String_Value", "");
>
> and now i wanna add it to a text label:
>
> I have this in top of my code
>
> final TextView test = (TextView) findViewById(R.id.test);
>
> and then if i wanna show the string everything works as it should.
>
> test.setText(s);
>
> if i try to show the int value with this
>
> test.setText(i);
>
> then my application make a force close, so i thougt that the problem
> was that i had to make the int a string so i did like this
>
>  test.setText(Integer.toString(i));
>
> now the program wotk but it does not show my stored value it shows me
> the in this case 200 becourse of
>
> int i = pref.getInt("Int_Value", 200);
>
> I must be missing something simple here i quess.
> could someone point it out for me?
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 
--------------------
Raghav Sood
CEO/Founder/Owner/Dictator/Tyrant at Appaholics (Basically all titles
required to have complete control)
http://www.raghavsood.com/
https://market.android.com/developer?pub=Appaholics
http://www.appaholics.in/

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to