EditText.getText()。getLength()在包含提示时是否返回0?

时间:2014-01-19 15:31:30

标签: android testing error-handling android-edittext

我有一些代码,但它没有按预期工作。我的逻辑似乎没有错,所以我认为这是一个实现错误。我的代码:

public boolean[] party_check(){
        Date date_ET = new Date(party_dateET.getYear(), party_dateET.getMonth(), party_dateET.getDayOfMonth());///Date is deprecated,
        ///but easy to handle
        ///this is used to test the date contained in the datepicker, party_dateET. If it is before the day today, then it will not write,
        ///and a message is displayed

        boolean[] return_array = new boolean[4];
        ///EditText party_titleET;
        ///EditText party_timeET;
        ///EditText party_dateET;
        ///EditText party_venueET;
        return_array[0] = true;
        if(party_titleET.getText().length() == 0){
            return_array[1] = false;
            return_array[0] = false;
        }else{
            return_array[1] = true;
        }
        if(date_ET.before(Calendar.getInstance().getTime()) == true){
            return_array[2] = false;
            return_array[0] = false;
            ///tests that the date entered is not invalid, ie. is in the future.
            ///not test for time. I could say that if time == 00:00, then don't run, or use a listener to check if it has changed,
            ///using a boolean value. But this would not really benefit the task much, so I haven't. It would also
            ///take more coding, and more complex coding.
        }else{
            return_array[2] = true;
        }
        if(party_venueET.getText().length() == 0){
            return_array[3] = false;
            return_array[0] = false;
        }else{
            return_array[3] = true;
        }
        return return_array;
        ///return_array[0] - 1st value in array - is used as toggle as to whether the party is ready or not.
        ///return_array[1-4] are used to indicate to the user which textbox is empty/ has a problem.



    }

然而,当我返回布尔数组时,它没有做我期望它做的事情。这用于测试用户是否在EditText中输入了文本值。 但是它没有按预期工作。我的逻辑是错误的,还是我错了?谢谢你的帮助!!

2 个答案:

答案 0 :(得分:4)

使用getText()时,不会返回提示。您可以使用getHint()

答案 1 :(得分:1)

文字和提示是不同的属性 因此,如果显示提示,则文本将为空。

让我们说提示是文本的“礼服”(不要让它“裸”),但它不是文本本身。