Android Learning-Interface-ui-searchview

Source: Internet
Author: User

Activity_main.xml

<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "${relativepackage}.${activityclass}"     >    <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_alignparentleft= "true"Android:layout_alignparenttop= "true"android:orientation= "vertical" >        <SearchviewAndroid:id= "@+id/searchview1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"             >        </Searchview>        <ListViewAndroid:id= "@+id/listview1"Android:layout_width= "Match_parent"Android:background= "#888"Android:layout_height= "Wrap_content" >        </ListView>    </LinearLayout></Relativelayout>
View Code

Mainactivity.java

 Public classMainactivityextendsActivity {Searchview searchView1;    ListView ListView1; string[] Items=Newstring[]{"Aaaaaaaaa", "bbbbbbbbb", "CCCCCCCCCC",            "AA", "BB", "CC"            }; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.activity_main); SearchView1=(Searchview) Findviewbyid (R.ID.SEARCHVIEW1); //Show Submit ButtonSearchview1.setsubmitbuttonenabled (true); //set to fetch is hidden to show only one iconSearchview1.seticonifiedbydefault (false); //hint hintSearchview1.setqueryhint ("Please enter filter conditions"); ListView1=(ListView) Findviewbyid (R.ID.LISTVIEW1); //binding a data setListview1.setadapter (NewArrayadapter<string>(Getapplicationcontext (), Android.        R.layout.simple_list_item_1,items)); //set Allow filteringListview1.settextfilterenabled (true); //Increase EventSearchview1.setonquerytextlistener (NewOnquerytextlistener () {@Override Public Booleanonquerytextsubmit (String query) {toast.maketext (Getapplicationcontext (),"You are inquiring:" +query, Toast.length_short). Show (); return true; } @Override Public BooleanOnquerytextchange (String newtext) {if(Textutils.isempty (NewText)) {listview1.cleartextfilter (); }Else{listview1.setfiltertext (NewText); }                return true;            }        }); }}
View Code

Android Learning-Interface-ui-searchview

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.