Android to monitor Edittex's picture implementation _android

Source: Internet
Author: User
Tags stub

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.