Super Simple Searchview "Android Custom View Combat"

Source: Internet
Author: User

Super Simple Searchview "Android Custom View Combat"
in Android Development we often use the search box, and the system does not provide perfect. So customize a relatively simple searchview.


Implementation Code
Package Cn.bluemobi.dylan.searchview;import Android.content.context;import Android.text.editable;import Android.text.textwatcher;import Android.util.attributeset;import Android.view.layoutinflater;import Android.view.view;import Android.widget.button;import Android.widget.edittext;import Android.widget.LinearLayout ;/** * Android Custom Searchview * Created by Yuandl */public class Searchview extends LinearLayout implements Textwatcher, Vi ew.    Onclicklistener {/** * input box */private EditText et_search;    /** * The Clear button after the input box */private button bt_clear;        Public Searchview (context context, AttributeSet Attrs) {Super (context, attrs);        /** Load Layout file */layoutinflater.from (context). Inflate (R.layout.pub_searchview, this, true);        /*** Find control */Et_search = (EditText) Findviewbyid (R.id.et_search);        Bt_clear = (Button) Findviewbyid (r.id.bt_clear);        Bt_clear.setvisibility (GONE);        Et_search.addtextchangedlistener (this); Bt_clear.Setonclicklistener (this); } @Override public void beforetextchanged (charsequence charsequence, int i, int i1, int i2) {} @Override P ublic void OnTextChanged (charsequence charsequence, int i, int i1, int i2) {}/**** * listening for user input text * @p Aram Editable */@Override public void aftertextchanged (editable editable) {/** get input text **/String I        Nput = Et_search.gettext (). toString (). Trim ();        if (Input.isempty ()) {bt_clear.setvisibility (GONE);        } else {bt_clear.setvisibility (VISIBLE);    }} @Override public void OnClick (view view) {Et_search.settext (""); }}


GitHub

Super Simple Searchview "Android Custom View Combat"

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.