[英]How can i use putdouble instead of put int
I wanna save the value of my textview in a onstop
and onpause
. 我想在
onstop
和onpause
保存textview的值。 But the value that is in the textview
is a double
, how can cast putint
to double
or use something else for it 但是
textview
的值是double
,如何将putint
为double
或对其使用其他内容
This is my code How can i solve this? 这是我的代码我该如何解决?
@Override
protected void onStop()
{
super.onStop();
savedValues.edit().putInt("price", (double)price).apply();
}
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
putString (String key, String value)
and then parse that into a double 然后将其解析为一个double
Double.parseDouble(myValueAsString);
尝试这个
savedValues.edit().putString("price",Double.parseDouble(price)).apply();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.