如果单击开始按钮,它将不会继续

If the start button is clicked, it will not proceed

我想申请寻找理想的锦标赛类型。下面的代码是一个函数,它在您按下“开始”按钮时启动。 'choice1' 和 'choice2' 是布尔值,在按下每个图像按钮时变为真。单击开始按钮时,仅按下按钮,不执行。 我是初学者,所以我不知道出了什么问题。帮帮我。

public class BoyWorldCup extends Activity {
    boolean choice1;
    boolean choice2;
    Button start;
    ImageButton image1, image2;
    TextView txt1, txt2;
    ArrayList<Integer> photoList;
    ArrayList<String> nameList;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.boy);
        int[] photos= {R.drawable.cha_enwoo, R.drawable.park_bogum,R.drawable.jung_heain,R.drawable.seo_gangjoon,
                R.drawable.gang_dongwon,R.drawable.gong_you,R.drawable.won_bin, R.drawable.ahn_hyosub};
        photoList = new ArrayList<>();
        for(int i : photos) {
            photoList.add(i);
        }
        String[] names ={"차은우","박보검","정해인","서강준","강동원","공유","원빈", "안효섭"};
        nameList = new ArrayList<>(Arrays.asList(names));

        start = (Button) findViewById(R.id.start);
        image1 = (ImageButton) findViewById(R.id.image1);
        image2 = (ImageButton) findViewById(R.id.image2);
        txt1 = (TextView) findViewById(R.id.txt1);
        txt2 = (TextView) findViewById(R.id.txt2);
        TextView roundTxt = (TextView) findViewById(R.id.roundTxt);

        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view){
                worldCup();
            }
        });
        image1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                choice1 = true;
            }
        });
        image2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                choice2 = true;
            }
        });
    }
    public void worldCup(){
        int round=8;
        while(true) {
            if (round == 1) {
                image1.setImageResource(photoList.get(0));
                txt1.setText("당신의 최종 이상형입니다.");
                break;
            }
            int i =0;
            while(true) {
                if (i == round) {
                    break;
                } else {
                    image1.setImageResource(photoList.get(i));
                    image2.setImageResource(photoList.get(i + 1));
                    txt1.setText(nameList.get(i));
                    txt2.setText(nameList.get(i + 1));
                    if (choice1) {
                        photoList.remove(i + 1);
                        nameList.remove(i + 1);
                        choice1 = false;
                        i = i + 2;
                    } else if (choice2) {
                        photoList.remove(i);
                        nameList.remove(i);
                        choice2 = false;
                        i = i + 2;
                    }
                }
                round = round / 2;
            }
        }
    }
}

由于您使用了嵌套循环,因此您应该命名外层循环,然后使用您刚刚设置的标签将其中断。

public void worldCup(){
        int round=8;
        outerloop: //label the loop
        while(true) {
            if (round == 1) {
                image1.setImageResource(photoList.get(0));
                txt1.setText("당신의 최종 이상형입니다.");
                break;
            }
            int i =0;
            while(true) {
                if (i == round) {
                    break outerloop; //break it
                } else {
                    image1.setImageResource(photoList.get(i));
                    image2.setImageResource(photoList.get(i + 1));
                    txt1.setText(nameList.get(i));
                    txt2.setText(nameList.get(i + 1));
                    if (choice1) {
                        photoList.remove(i + 1);
                        nameList.remove(i + 1);
                        choice1 = false;
                        i = i + 2;
                    } else if (choice2) {
                        photoList.remove(i);
                        nameList.remove(i);
                        choice2 = false;
                        i = i + 2;
                    }
                }
                round = round / 2;
            }
        }
    }