This article for everybody to share the Edittex picture realizes the monitoring method, for everybody reference, the concrete content is as follows
First example: monitor the picture on the right side of the EditText
Gets the rightmost X2 coordinate of the edittext minus the X1 coordinate point of the rightmost picture, and performs a listening event when the click of the x coordinates is between the 2 x
Final EditText EditText = (edittext) Findviewbyid (R.ID.ZSM);
Edittext.setontouchlistener (New Ontouchlistener () {
final int drawable_left = 0;
final int drawable_top = 1;
final int drawable_right = 2;
Final int drawable_bottom = 3;
@Override Public
Boolean Ontouch (View V, motionevent event) {
if (Event.getx () >= (Edittext.getright ()-Editt Ext
. Getcompounddrawables () [Drawable_right].getbounds ()
. Width ())] {
Toast.maketext ( Getapplicationcontext (), "AAAA", 1000. Show ();
return false;
}
});
A second example:
We want to implement: when EditText text changes, we want to be notified, but unfortunately Android does not have this listener, and there is no way to know the change, but we can use the Textwatcher class can help us to achieve this function.
An existing id = edit EditText.
1, to define a Textwatcher instance.
Private Textwatcher watcher = new Textwatcher () {
@Override public
void aftertextchanged (Editable s) {
// TODO auto-generated method Stub
}
@Override public
void beforetextchanged (charsequence s, int start, int Count, int after) {
//TODO auto-generated a stub
}
@Override public
void OnTextChanged ( charsequence s, int start, int before, int count) {
log.d ("TAG", "[textwatcher][ontextchanged]" +s);
2, register the Textwatcher instance on the EditText.
EditText et = (edittext) Findviewbyid (r.id.edit);
Et.addtextchangedlistener (watcher);
So whenever the text of EditText changes, ontextchanged () will be called!
The above is on the Android edittext control monitoring events, I hope to help you learn, but also hope that we support the cloud habitat community.