라디오 그룹1에는 아메리카노, 카페라떼, 카푸치노
라디오 그룹2에는 스몰, 미디움, 라지
에 따른 가격을 각각 만들었는데
계산 버튼 클릭시 합쳐진 값을 출력하고 싶습니다.
계산 버튼 눌렀을 때 다 3000원이 나오게 되는데 어떤 부분이 잘못된 걸까요...
어떻게 고쳐야 제대로 된 값들이 나오게 될까요
(계산 부분에 볼드 처리 해놨습니다!)
/////////
import static android.widget.RadioGroup.*;
public class MainActivity extends AppCompatActivity {
RadioGroup group, group2;
RadioButton button1, button2, button3, button4,button5, button6;
ImageView image;
String str = "";
RadioGroup radioGroup, radioGroup2;
TextView tv,Result;
Button button;
private View.OnClickListener r;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
group = (RadioGroup) findViewById(R.id.radioGroup);
button1 = (RadioButton) findViewById(R.id.Ame);
button2 = (RadioButton) findViewById(R.id.Cafe);
button3 = (RadioButton) findViewById(R.id.Capu);
group2 = (RadioGroup) findViewById(R.id.radioGroup2);
button4 = (RadioButton) findViewById(R.id.Small);
button5 = (RadioButton) findViewById(R.id.Medium);
button6 = (RadioButton) findViewById(R.id.Large);
//이벤트 대상과 리스너(감지기) 등록
button = (Button) findViewById(R.id.button);
button1.setOnClickListener(radio_listener);
button2.setOnClickListener(radio_listener);
button3.setOnClickListener(radio_listener);
button4.setOnClickListener(radio_listener);
button5.setOnClickListener(radio_listener);
button6.setOnClickListener(radio_listener);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup2 = (RadioGroup) findViewById(R.id.radioGroup2);
image = (ImageView) findViewById(R.id.imageView);
tv = (TextView) findViewById(R.id.textView);
Result = (TextView) findViewById(R.id.Result);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.Ame) {
Toast.makeText(MainActivity.this, "아메리카노 선택", Toast.LENGTH_SHORT).show();
} else if (checkedId == R.id.Cafe) {
Toast.makeText(MainActivity.this, "카페라떼 선택", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "카푸치노 선택", Toast.LENGTH_SHORT).show();
}
}
});
radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.Small) {
Toast.makeText(MainActivity.this, "Small 선택", Toast.LENGTH_SHORT).show();
} else if (checkedId == R.id.Medium) {
Toast.makeText(MainActivity.this, "Medium 선택", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Large 선택", Toast.LENGTH_SHORT).show();
}
}
});
}
public void button(View view)
{
if(view == 1 && view == 4)
{
Result.setText("1000원")
}
else if(view == 1 && view == 5)
{
Result.setText("1500원")
}
else if(view == 1 && view == 6)
{
Result.setText("2000원")
}
else if(view == 2 && view == 4)
{
Result.setText("1500원")
}
else if(view == 2 && view == 5)
{
Result.setText("2000원")
}
else if(view == 2 && view == 6)
{
Result.setText("2500원")
}
else if(view == 3 && view == 4)
{
Result.setText("2000원")
}
else if(view == 3 && view == 5)
{
Result.setText("2500원")
}
else if
{
Result.setText("3000원")
}
}