Mit der Idee "CustomTextWatcher" habe ich das gemacht
1) Eine neue TextWatcherListener-Schnittstelle erstellt:
public interface TextWatcherExtendedListener extends NoCopySpan
{
public void afterTextChanged(View v, Editable s);
public void onTextChanged(View v, CharSequence s, int start, int before, int count);
public void beforeTextChanged(View v, CharSequence s, int start, int count, int after);
}
2) Erstellt und verwendet EditTextExtended anstelle von EditText (in meinem Fall):
public class EditTextExtended extends EditText
{
private TextWatcherExtendedListener mListeners = null;
public EditTextExtended(Context context)
{
super(context);
}
public EditTextExtended(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public EditTextExtended(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
public void addTextChangedListener(TextWatcherExtendedListener watcher)
{
if (mListeners == null)
{
mListeners = watcher;
}
}
public void removeTextChangedListener(TextWatcherExtendedListener watcher)
{
if (mListeners != null)
{
mListeners = null;
}
}
void sendBeforeTextChanged(CharSequence text, int start, int before, int after)
{
if (mListeners != null)
{
mListeners.beforeTextChanged(this, text, start, before, after);
}
}
void sendOnTextChanged(CharSequence text, int start, int before,int after)
{
if (mListeners != null)
{
mListeners.onTextChanged(this, text, start, before, after);
}
}
void sendAfterTextChanged(Editable text)
{
if (mListeners != null)
{
mListeners.afterTextChanged(this, text);
}
}
}
3) Also, wo Sie diesen Code schreiben müssen:
myEditTextExtended.addTextChangedListener(this)
4) benutze sie:
@Override
public void onTextChanged(View v, CharSequence s, int start, int before, int count)
{
}
@Override
public void beforeTextChanged(View v, CharSequence s, int start, int count, int after)
{
}
@Override
public void afterTextChanged(View v, Editable s)
{
}
Lassen Sie mich wissen, was Sie denken.