Android:用户键入EditText时创建倒计时字字段
我想在Android:用户键入EditText时创建倒计时字字段,android,Android,我想在TextView中显示一个计数器,它随着用户在EditText中写入的字符数而减少 我有一个TextView来显示110个字符的计数器,109、108、107 wordCount = (TextView) findViewById(R.id.nouvelle_annonce_words_count) ; 我有一个EditText,用户在其中写道: title = (EditText) findViewById(R.id.nouvelle_annonce_titre) ; 我如何监听Ed
TextView
中显示一个计数器,它随着用户在EditText中写入的字符数而减少
我有一个TextView
来显示110个字符的计数器,109、108、107
wordCount = (TextView) findViewById(R.id.nouvelle_annonce_words_count) ;
我有一个EditText,用户在其中写道:
title = (EditText) findViewById(R.id.nouvelle_annonce_titre) ;
我如何监听EditText中的更改并用剩余字符数更新我的textView?您可以像这样使用
addTextChangedListener
title.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
wordCount.setText(String.valueOf(110 - (title.getText().toString().length)));
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
你想做的事叫做 可能重复的
title.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
wordCount.setText(String.valueOf(110-s.length()));
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});