자바에서 Android 용 기본 계산기를 만들고 있습니다. 나는 이전 입력으로 입력을 추가해야하는 마지막 단계에 갇혀있다. 코드에서보세요 :내 안드로이드 계산기 작동 방법
public void displayValue(){
String mything = display.getText().toString();
input = Integer.parseInt(mything);
}
public void number1(View view){
if (input == 0){display.setText("");}
display.append(Integer.toString(1));
displayValue();
}
public void number2(View view){
if (input == 0){display.setText("");}
display.append(Integer.toString(2));
displayValue();
}
public void plus(View view){
displayValue(); //result= 0
result = result + input; //result= input
input = 0; //input=0
//in this step input becomes 0 to let the user enter new number input but this
//input never add the old result and the equal shows the old result.
}
public void equal(View view){
displayValue();
display.setText(Integer.toString(result));
}
은 내가 입력과 동일한 방법으로 행을 추가하고 결과를 추가하면 제가 정확한 답변을 얻을하지만 너무 마이너스 버튼을있을 것 같은 그런 거 도움이 될 아니에요 것으로 나타났습니다.
아이디어가 있으십니까?
감사합니다.
예상되는 결과가 어디서 어떤 결과를 얻었는지 조금 더 잘 설명 할 수 있습니까? – codeMagic
@codeMagic OK. 그것은 계산기입니다. 사용자는 몇 개의 숫자를 누릅니다. 'displayValue'메소드는 'input'에 저장된 int로 변경하고, 사용자가 + 또는 - 버튼을 누르면 'result'변수에 입력 한 숫자를 저장합니다. 그러면 입력이 다시 0이되고 사용자가 계산의 다른 쪽을 입력합니다. 그런 다음 등호를 눌러 결과를 얻습니다. 따라서 결과에 저장된 값은 두 번째 입력을 빼거나 더하고 결과를 화면에 표시합니다. 이것이 어떻게 작동하는지입니다. 하지만 제 문제는 두 번째 입력으로 결과를 계산할 수있는 기회를 얻지 못한다는 것입니다. –