当EditText.getText().getLength()包含提示时,它是否返回0? [英] Does EditText.getText().getLength() return 0 when it contains a hint?

查看:196
本文介绍了当EditText.getText().getLength()包含提示时,它是否返回0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,但是无法正常工作.我的逻辑似乎没有错,所以我认为这是实现错误.我的代码:

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中输入了文本值. 但是,它不能按预期方式工作.我的逻辑有误吗,或者我实现错误?感谢您的帮助!

解决方案

使用getText()时不会返回提示.不过,您可以使用 getHint() ./p>

I have some code, but it is not working as expected. My logic doesn't seem to be faulty, so I think it is an implementation error. My code:

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.



    }

However it does not do what I expect it to do when I return the boolean array. This is used for testing whether the user has entered a text value into the EditText's. However it does not work as expected. Is my logic faulty, or I have implemented it wrong? Thanks for the help!!

解决方案

The hint does not get returned, when you use getText(). You can use getHint() though.

这篇关于当EditText.getText().getLength()包含提示时,它是否返回0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆