RadioButton sex = (RadioButton) findViewById(sexGroup.getCheckedRadioButtonId());
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
float chText = checkText();
if( chText == 0 ){
float h = Float.parseFloat(mHeightText.getText().toString());
float w = Float.parseFloat(mWeightText.getText().toString());
double fRate = ( w / ((h-100) * 0.9) ) * 100;
두개의 라디오 버튼중 선택한 버튼에 따라 색칠한 부분 계산식을 두가지로 나누고싶은데
어떻게 수정을 해야할까요....ㅠ
mHeightText = (EditText)findViewById(R.id.val_height);
mWeightText = (EditText)findViewById(R.id.val_weight);
mResultView = (TextView)findViewById(R.id.rst_text);
okButton = (Button)findViewById(R.id.ok);
RadioGroup sexGroup = (RadioGroup) findViewById(R.id.sex);
final RadioButton sex = (RadioButton) findViewById(sexGroup.getCheckedRadioButtonId());
public void onClick(View v) {
float chText = checkText();
if( chText == 0){
float h = Float.parseFloat(mHeightText.getText().toString());
float w = Float.parseFloat(mWeightText.getText().toString());
if(v.getId() == sex.getId()){
double fRate = ( w / ((h-100) * 0.9) ) * 100;
}
else{
double fRate = ( w / ((h-100) * 0.8) ) * 100;
}
String str_result;
if(fRate > 110){
str_result = "비만";
}
else if(fRate < 90){
str_result = "저체중";
}
else{
str_result = "정상체중";
}
str_result = String.format("표준체중기준"+"%.2f", fRate) + "%\n" + str_result;
mResultView.setText(str_result);
}
else if(chText == 1){
mResultView.setText("키와 몸무게를 입력하세요");
}
else if(chText == 2){
mResultView.setText("키와 몸무게를 숫자로 입력하세요");
}
}
});
}
이런식으로 수정해봤는데
sex부분과 fRate부분이 빨간줄가네요
sex부분은 RadioButton sex = (RadioButton) findViewById(sexGroup.getCheckedRadioButtonId()); 앞에 파이널 붙여주니까
빨간줄 없어지긴하던데
fRate는 어떻게 해결해야할지....ㅠ
수고스럽겠지만 한번만 더 알려주세요



