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"