Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,730,865 Members 45,015 Now Online
XDA Developers Android and Mobile Development Forum

Shared preferences and textview

Tip us?
 
mistere372002
Old
#1  
mistere372002's Avatar
Senior Member - OP
Thanks Meter 44
Posts: 218
Join Date: May 2010
Location: Tucson

 
DONATE TO ME
Default Shared preferences and textview

I originally asked this question in Srackoverflow. But I did not get any answers.

I am trying to set a text view number value to shared preferences using a string to get the values. Can anyone help with this?

Sent from my SGH-M919 using XDA Premium 4 mobile app
 
painlessDeath
Old
#2  
Junior Member
Thanks Meter 2
Posts: 13
Join Date: Feb 2013
Quote:
Originally Posted by mistere372002 View Post
I am trying to set a text view number value to shared preferences using a string to get the values
Could you elaborate on this?
You want to store the text (which is a number) in the textview to shared preferences?

Code:
  mPrefs.edit().putInt("my-key", Integer.parse(mTextView.getText().toString())).commit();
 
mistere372002
Old
(Last edited by mistere372002; 16th March 2014 at 11:05 PM.)
#3  
mistere372002's Avatar
Senior Member - OP
Thanks Meter 44
Posts: 218
Join Date: May 2010
Location: Tucson

 
DONATE TO ME
That's correct. I forgot to mention that the number could be a decimal also.

Sent from my SGH-M919 using XDA Premium 4 mobile app
 
mistere372002
Old
#4  
mistere372002's Avatar
Senior Member - OP
Thanks Meter 44
Posts: 218
Join Date: May 2010
Location: Tucson

 
DONATE TO ME
Thanks painless, that worked perfectly!

Sent from my SGH-M919 using XDA Premium 4 mobile app
 
steelthunder100
Old
#5  
Junior Member
Thanks Meter 0
Posts: 14
Join Date: Dec 2013
Default Storing Chronometer time in SharedPreferences

Quote:
Originally Posted by mistere372002 View Post
Thanks painless, that worked perfectly!

Sent from my SGH-M919 using XDA Premium 4 mobile app
I am actually trying to store the value of a chronometer in SharedPreferences but admittedly I have not worked with SharedPreferences much.

My end goal is to be able to close the Chronometer app and have the chronometer pick up from where it left off when the app is close.

Any help is appreciated.



Code:
 chronometer = (Chronometer) findViewById(R.id.Chronometer1);

public void startClick (View view){
    	 	
    
    	
    	
    	 chronometer.setBase(SystemClock.elapsedRealtime());
         chronometer.start();
         Vibrator vib = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
 		vib.vibrate(100);
        }
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes