繁体   English   中英

按钮条件

[英]Condition for Button

我想为 ShowSolution 按钮添加一个条件。 当您按下作为我的 AnswerCheck 方法的提交按钮时,只有当您能够按下“显示解决方案”按钮时。 有没有办法做到这一点? 感谢您的帮助,谢谢。

public void AnswerCheck2(View view) {

        EditText num2 = (EditText) findViewById(R.id.answertext2);
        int val2 = Integer.parseInt(num2.getText().toString());


        area = number3 * number3;

        if (val2 == area) {
            Toast.makeText(this, "The answer is correct", Toast.LENGTH_SHORT).show();

        } else {

            Toast.makeText(this, "The answer is incorrect ", Toast.LENGTH_SHORT).show();
        }

    }

    public void ShowSolution2(View view){
        ((TextView) findViewById(R.id.solution2)).setText
                ("The Solution is "+number3 + " * " +number3);

        ((TextView) findViewById(R.id.answer2)).setText("The answer is "+area);
    }


}

如果我正确理解您的问题,则有多种方法可以根据条件启用/显示按钮,例如:

  • button.setEnabled(true)
  • button.setVisibility(VISIBLE)

其中button是您通过调用findViewById(id)获得的按钮。

当然,这也意味着您的按钮之前被禁用或隐藏,但如果没有进一步解释,很难提供指导。

据我了解,您首先希望用户提交他们的答案,然后只有在提交他们的答案后,才能显示解决方案按钮。

然后在这种情况下使用这个: -

最初在 oncreate 方法中:- solutionbutton.setvisibility(false)

然后在 answercheck2:- Solutionbutton.setvisibility.setvisibility(true) num2.setfocusable(false)

通过这种方式,您还可以控制用户稍后更改那里的答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM