gpt4 book ai didi

java - setOnFocusChangeListener 重新添加提示

转载 作者:太空宇宙 更新时间:2023-11-04 15:14:51 26 4
gpt4 key购买 nike

我有一个 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");
}

});

感谢帮助

最佳答案

而不是

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)

然后在 ontext 中更改 ltener

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) {}
});

关于java - setOnFocusChangeListener 重新添加提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20946696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com