【发布时间】:2011-05-17 16:01:25
【问题描述】:
在我的项目中,我有一个EditText。我想计算EditText 中的字符,并在TextView 中显示该数字。我已经编写了以下代码,它工作正常。但是,我的问题是当我单击 Backspace 时它会增加,但我需要减少数字。如何考虑 Backspace?
tv = (TextView)findViewById(R.id.charCounts);
textMessage = (EditText)findViewById(R.id.textMessage);
textMessage.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
i++;
tv.setText(String.valueOf(i) + " / " + String.valueOf(charCounts));
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){}
});
【问题讨论】:
-
请原谅无关紧要,但我很好奇您是如何在问题格式中放置“退格”的?我已经问过类似的问题,该技术会非常有用。
-
将您的单词(在本例中为 Backspace)放在 标记之间,例如:Backspace
-
每当你看到有趣的格式(比如“退格”),你总是可以点击“编辑”链接看看作者是怎么做的。然后只需单击“取消”即可放弃您的编辑。
标签: android listener android-edittext onchange