EditText automatically retrieve fields, Textwatcher

Source: Internet
Author: User

public class Mainactivity extends Activity {


Private EditText edit;

Private ListView list;

Private string[] str = new string[] {"1232", "45", "4631", "123485",

"87894", "4156", "1564", "5465", "45612", "98", "1247", "59789",

"7897862", "578631", "48876", "215", "2148", "7985"};

Arrayadapter adapter;


@Override

public void OnCreate (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);

Setcontentview (R.layout.item);

Edit = (EditText) Findviewbyid (R.id.edit);

List = (ListView) Findviewbyid (r.id.list);

adapter = new Arrayadapter (Mainactivity.this, R.layout.window,

R.id.text, str);

List.setadapter (adapter);

Edit.setonkeylistener (New Onkeylistener () {

@Override

public boolean OnKey (View arg0, int keycode, keyevent keyevent) {

if (keycode = = Keyevent.keycode_del) {

/**

* Every time you delete, even if you update the list

* */

EditText edit = (EditText) arg0;

Adapter.getfilter (). Filter (Edit.gettext (). toString ());

Adapter.notifydatasetchanged ();

}

return false;

}


});

Edit.addtextchangedlistener (New Textwatcher () {


@Override

public void aftertextchanged (Editable s) {

String str_new = s.tostring ();

/**

* Filter out the established string using the filter field

* */

Adapter.getfilter (). filter (s);

Adapter.notifydatasetchanged ();

}


@Override

public void beforetextchanged (charsequence s, int start, int end,

int count) {


}


@Override

public void ontextchanged (charsequence s, int start, int end,

int count) {


}

});

}

}


This article is from the "Qing gan tea" blog, please be sure to keep this source http://shunshuncon.blog.51cto.com/8232441/1640116

EditText automatically retrieve fields, Textwatcher

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.