0

I wanna save the value of my textview in a onstop and onpause. But the value that is in the textview is a double, how can cast putint to double or use something else for it

This is my code How can i solve this?

     @Override
        protected void onStop()
        {
            super.onStop();
            savedValues.edit().putInt("price", (double)price).apply();
        }
Shawn Mehan
  • 4,513
  • 9
  • 31
  • 51
jason tp
  • 9
  • 1

2 Answers2

0

Try storing a float but if loosing the precision is an Killing issue then consider storing that as String by calling the method putString

 putString (String key, String value)

and then parse that into a double

Double.parseDouble(myValueAsString); 
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • @Override protected void onStop() { super.onStop(); savedValues.edit().putInt("price",Double.parseDouble(myValueAsString);.apply(); } like this ? – jason tp May 10 '17 at 17:34
0

try this

 savedValues.edit().putString("price",Double.parseDouble(price)).apply(); 
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Ege Kuzubasioglu
  • 5,991
  • 12
  • 49
  • 85
  • parseDouble returns double, which can't be used with `putString` – OneCricketeer May 10 '17 at 17:44
  • 1
    it says Double cannot applied to java.long,Double – jason tp May 10 '17 at 17:48
  • While this code snippet may be the solution, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-‌​code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – milo526 May 10 '17 at 18:35