【发布时间】:2015-02-27 13:08:45
【问题描述】:
我目前正在创建一个应用程序,该应用程序将值相加以得出总体总数,就像这样。 oldValue + newValue = textView1...
MainActivity,这是在 textView1 中存储整体值的地方
String calorie = getIntent().getStringExtra("calorie");
TextView textView1 = (TextView)findViewById(R.id.textView1);
String strOldValue = textView1.getText().toString();
Integer oldValue;
try{
oldValue= Integer.parseInt(myString);
}catch(NumberFormatException e){
oldValue =0;
}
Integer newValue;
try{
newValue= Integer.parseInt(calorie);
}catch(NumberFormatException e){
newValue =0;
}
textView1.setText((oldValue + newValue));
问题是 textview 忘记了旧值而只是插入新值...所以携带 100,然后我去添加 150...我只看到 150。相信我需要存储100(oldValue)某处。有什么建议吗?
上下文:这是一个食物计算器,它使用 AddActivity 和 MainActivity 添加食物卡路里。
【问题讨论】:
-
这里的 myString 是什么?
-
代码 sn-p 未显示 myString 的值来自何处。
-
从我的 AddActivity 类中携带的一个字符串,包含 newValue。
标签: java android android-studio sharedpreferences calculator