我有EditText
提示“最多20个字符”,当我点击它时,它会消失setOnClickListener
和setHint
。
但是现在我想重新添加提示,如果这个人没有放任何东西......
现在有我的代码:
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");
}
});
感谢您的帮助
答案 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) {}
});