Copyright (C) 2013 Madis Pink
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softwa...
If you think the Android project bad listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.madisp.bad.lib.ui;
//www.java2s.comimport android.text.Editable;
import android.text.TextWatcher;
import android.widget.TextView;
import com.madisp.bad.eval.BadConverter;
import com.madisp.bad.eval.BadVar;
/**
* Created with IntelliJ IDEA.
* User: madis
* Date: 3/23/13
* Time: 6:45 PM
*/publicclass BadTextWatcher implements TextWatcher, BadVar.BadWatcher<String> {
private BadVar<String> var;
private TextView tv;
public BadTextWatcher(TextView tv, BadVar<String> var) {
this.var = var;
this.tv = tv;
var.addWatcher(this);
}
@Override
publicvoid beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
publicvoid onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
publicvoid afterTextChanged(Editable s) {
if (!s.toString().equals(var.get())) {
var.set(s.toString(), this);
}
}
@Override
publicvoid fire(BadVar<String> var) {
String newValue = BadConverter.string(var);
if (!tv.getText().toString().equals(newValue)) {
tv.setText(newValue);
}
}
}