我想在android中设置一个监听器,以便知道我的字段何时更改(整数);并更新一个textview它的变化...有没有办法将侦听器设置为在android中更改以更新TextView的字段?
不知道该怎么办?
这有可能吗?
我想在android中设置一个监听器,以便知道我的字段何时更改(整数);并更新一个textview它的变化...有没有办法将侦听器设置为在android中更改以更新TextView的字段?
不知道该怎么办?
这有可能吗?
您正在寻找onTextChanged,也许? 第1步:
public void onTextChanged(CharSequence s, int start,
int before, int count) {
///code
}
PD:谷歌是相当聪明,你应该问他更多的时候。他会很乐意提供帮助。
事情是;我不听TextView的改变;我正在侦听一个整型字段(int someNumber)来更改它在类头中。当它确实改变时,用它设置TextView。 – Nevily
您可以在EditText上使用TextWatcher。检查下面的例子
mEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
// Here you will get complete text from edittext after text changed
// do your task
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Here you will get complete text from edittext before text changed
// do your task
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Here you can check 's' is number or not. It it is number you can set that number to your textview with your own logic
// do your task
}
});
希望这会帮助你。
不要忘记投票了:)
Cheerz
为什么你想这样做呢?如果**你**或**你的方法**改变你的字段,为什么不能在'TextView'上调用'setText(..)'?在这种情况下,没有必要引入听众,这将是矫枉过正的 – Drew