나는 현재 전체 합계를 제공하기 위해 값을 더하는 응용 프로그램을 만들고 있습니다. 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 만 표시됩니다. A는 100을 저장해야한다고 믿습니다 ( oldValue) 어딘가에. 어떤 충고?
컨텍스트 : AddActivity 및 MainActivity를 사용하여 음식 칼로리를 추가하는 음식 계산기입니다.
MainActivity에서 정적 변수를 사용하십시오.
static int count=0;
가치를 얻다
String calorie = getIntent().getStringExtra("calorie");
그리고 그것을 추가하십시오
count+=Integer.parseInt(calorie);
값을 edittext로 설정하십시오.
textView1.setText(count+"");
이것이 도움이되기를 바랍니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다