setOnFocusChangeListener重新添加提示

时间:2014-01-06 09:24:08

标签: java android

我有EditText提示“最多20个字符”,当我点击它时,它会消失setOnClickListenersetHint。 但是现在我想重新添加提示,如果这个人没有放任何东西......

现在有我的代码:

entry01.setOnFocusChangeListener(
            new OnFocusChangeListener() {
                public void onFocusChange(View v, boolean hasFocus) {
                    prenom = entry01.getText().toString();
                    if(entry01.getText().toString().equals(""));
                            entry01.setHint("20 lettres max");
                }
            });

    entry01.addTextChangedListener(new TextWatcher() {


        public void afterTextChanged(Editable s) {
            if(entry01.getText().toString().equals(""))
                entry01.setHint("20 lettres max");
        }


        public void beforeTextChanged(CharSequence s, int start, int count,int after) {

        }


        public void onTextChanged(CharSequence s, int start, int before,int count) {
            if(entry01.getText().toString().equals(""))
                entry01.setHint("20 lettres max");
        }

    });

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

而不是

entry01.setOnFocusChangeListener(
new OnFocusChangeListener() {
    public void onFocusChange(View v, boolean hasFocus) {
        prenom = entry01.getText().toString();
        if(entry01.getText().toString().equals(""));
                entry01.setHint("20 lettres max"); // means "20 character max"
        }
    });

使用

entry01.addtextchangelintener(new TextWatcher)

然后在上下文中更改侦听器

if((start + count) > 0)
{ entry01.setHint("20 lettres max"); }

或者你也可以使用你的代码

if(entry01.getText().toString().equals(""));
            entry01.setHint("20 lettres max"); // means "20 character max"

编辑:

这样做

receiverName.addTextChangedListener(new TextWatcher() 
    {
        @Override
        public void onTextChanged(CharSequence paramCharSequence, int paramInt1,int paramInt2, int paramInt3) 
        {
            if((start + count) > 0)
            { entry01.setHint("20 lettres max"); }

            //if(entry01.getText().toString().equals(""));
          //  entry01.setHint("20 lettres max");
        }

        @Override
        public void beforeTextChanged(CharSequence paramCharSequence,int paramInt1, int paramInt2, int paramInt3) {}

        @Override
        public void afterTextChanged(Editable paramEditable) {}
    });