package edu.apsu.assignment4;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View.OnClickListener;
import android.widget.RadioGroup;
import android.widget.CheckBox;
import android.widget.TextView;
public class MainActivity extends Activity implements
android.view.View.OnClickListener, CompoundButton.OnCheckedChangeListener {
Button sendButton,aboutButton;
EditText DrinkNum;
Double subtotal;
TextView order,aboutApp,Sroom,drinkType,Croom,go,flavor;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RadioGroup drink = (RadioGroup) findViewById(R.id.drinks);
drink.setOnClickListener(this);
CheckBox Croom = (CheckBox) findViewById(R.id.cream);
Croom.setOnCheckedChangeListener(this);
DrinkNum=(EditText) findViewById(R.id.editText1);
sendButton=(Button) findViewById(R.id.send);
sendButton.setOnClickListener(this);
aboutButton=(Button) findViewById(R.id.about);
aboutButton.setOnClickListener(this);
}
@Override
public void onClick(android.view.View v) {
RadioGroup drinkGroup = (RadioGroup) findViewById(R.id.drinks);
switch (drinkGroup.getCheckedRadioButtonId()) {
case R.id.coffee:
drinkType.setText("coffee");
subtotal=2.50;
break;
case R.id.cappuccino:
drinkType.setText("cappuccinno");
subtotal=4.50;
break;
case R.id.espresso:
drinkType.setText("espresso");
subtotal=4.50;
case R.id.latte:
drinkType.setText("latte");
subtotal=4.50;
break;
case R.id.iced_latte:
drinkType.setText("iced_latte");
subtotal=5.00;
break;
}
order.setText("Subtotal: "+subtotal+ "Tax: "+subtotal*.09+"Total: "+subtotal+subtotal*.09);
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Croom= (TextView) findViewById(R.id.cream);
Sroom= (TextView) findViewById(R.id.sugar);
go= (TextView) findViewById(R.id.go);
flavor= (TextView) findViewById(R.id.flavoring);
if (buttonView.getId() == R.id.cream) {
if (isChecked) {
Croom.setText("Room for cream");
} else {
Croom.setText("No room for cream");
}
}
else if (buttonView.getId() == R.id.sugar) {
if (isChecked) {
Sroom.setText("Room for sugar");
} else {
Sroom.setText("No room for sugar");
}
}
else if (buttonView.getId() == R.id.go) {
if (isChecked) {
go.setText("To go");
} else {
go.setText("Stay");
}
}
else if (buttonView.getId() == R.id.chocolate) {
if (isChecked) {
flavor.setText("Chocolate flavoring");
}
}
else if (buttonView.getId() == R.id.cherry) {
if (isChecked) {
flavor.setText("Cherry flavoring");
}
}
else if (buttonView.getId() == R.id.vanilla) {
if (isChecked) {
flavor.setText("Vanilla flavoring");
}
}
aboutButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg7) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "*In boxer announcer voice*: "+"\n"+"Credit is given to me.", Toast.LENGTH_LONG).show();
}
});
sendButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg8) {
String message;
message = "Number of cups: "+DrinkNum+"\n"+go+"\n"
+Croom+"\n"+Sroom+"\n"+"Drink type: "+drinkType+"\n"+"Flavoring: "+flavor
+"\n"+"Price details: "+order+"\n"+"Thanks for ordering";
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
});
}
}
2 番目のトースト メッセージで、以前のコードからの情報が関連付けられていません。また、ラジオボタンを1つだけ選択することはできません。他のボタンをクリックすると、それらも選択されます。この 2 つの問題を解決するにはどうすればよいですか?