我想实现EditText获得焦点和文本将要变化时做一些操作,但是下面的代码 onBeginBatchEdit 这种的执行不是预期的,大家指点一下应该怎么做?
package com.example.ebaypricing.app.component;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;
/**
* Created by xinyihai on 2014/8/19.
*/
public class NumberEditText extends EditText {
TextWatcher textWatcher;
public NumberEditText(android.content.Context context) {
super(context);
}
public NumberEditText(android.content.Context context, android.util.AttributeSet attrs) {
super(context, attrs);
}
public NumberEditText(android.content.Context context, android.util.AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
super.onTextChanged(text, start, lengthBefore, lengthAfter);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (textWatcher == null){
textWatcher = new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
Log.i("NumberEditText", "beforeTextChanged");
}
@Override
public void afterTextChanged(Editable editable) {
Log.i("NumberEditText", "afterTextChanged");
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
Log.i("NumberEditText", "onTextChanged");
}
};
this.addTextChangedListener(textWatcher);
}
}
@Override
public void onBeginBatchEdit() {
// Log.i("NumberEditText", "onBeginBatchEdit");
super.onBeginBatchEdit();
}
@Override
public void onEndBatchEdit() {
// Log.i("NumberEditText", "onEndBatchEdit");
super.onEndBatchEdit();
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
Log.i("NumberEditText", ("onFocusChanged:"+String.valueOf(focused) +" - "+ this.getTag()));
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
}