检查edittext文本总是返回false

时间:2014-12-20 08:10:26

标签: java android

我试图从编辑文本中获取文本并检查它是真还是假,如果没有显示错误消息

        correcttxt=correctans.getText().toString();

 if ((!correcttxt.equals("True")) || (!correcttxt.equals("False"))){
            AlertDialog.Builder alertBuilder=new AlertDialog.Builder(AdminAdd4.this);
            alertBuilder.setTitle("Invalid");
            alertBuilder.setMessage("The correct answer should be True or False.");
            alertBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            alertBuilder.create().show();
        }
    else {
                //confirmation to add exercise
                AlertDialog.Builder alertBuilder=new AlertDialog.Builder(AdminAdd4.this);
                alertBuilder.setTitle("Add Exercise");
                alertBuilder.setMessage("Are you sure you want to add this exercise?");
                alertBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                    new CreateNewexercise().execute();

                    }
                });
                alertBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                            }
                        });
                alertBuilder.create().show();
            }

但即使文字为True或False我也不知道为什么会显示错误信息?

有人可以帮忙吗?谢谢你:))

0 个答案:

没有答案