add the order restriction

This commit is contained in:
2018-11-07 14:38:23 +08:00
parent e711822f5e
commit 2e94f9c993
3 changed files with 34 additions and 10 deletions

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,15 +1,12 @@
package me.jj97181818.ch05_foodmenueventhw;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
@ -50,13 +47,34 @@ public class MainActivity extends AppCompatActivity implements CompoundButton.On
public void takeOrder(View v) {
String msg = "";
for (CompoundButton chk:selected)
msg += "\n" + chk.getText();
if (selected.size() == 3) {
for (CompoundButton chk:selected)
msg += "\n" + chk.getText();
if(msg.length() > 0)
msg = "你點購的餐點是:" + msg;
else
msg = "你點購的餐點是:" + msg + "\n總共是 50 元。";
}
else if (selected.size() == 4) {
for (CompoundButton chk:selected)
msg += "\n" + chk.getText();
msg = "你點購的餐點是:" + msg + "\n總共是 60 元。";
}
else if (selected.size() == 0){
msg = "請點餐!";
}
else if (selected.size() > 4) {
msg = "點餐不得點超過 4 樣。";
}
else {
msg = "點餐不得點少於 3 樣。";
}
// if(msg.length() > 0)
//
// else
// msg = "請點餐!";
((TextView) findViewById(R.id.showOrder)).setText(msg);
}

View File

@ -79,7 +79,7 @@
android:layout_marginEnd="8dp"
android:layout_marginBottom="165dp"
android:text="請點餐"
android:textSize="30sp"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"