Android in Searchview

Source: Internet
Author: User

 PackageCom.example.euphemiaxiao.classsearch;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;//import Android.support.v7.widget.SearchView;ImportAndroid.widget.SearchView;Importandroid.text.TextUtils;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.ListView; Public classClasssearchextendsAppcompatactivityImplementssearchview.onquerytextlistener{PrivateSearchview SV; PrivateListView LV; PrivateArrayadapter<string>adapter; Private FinalString[] mstrings={"2014211501", "2014211502", "2014211503", "2014211504",                                     "2015211501", "2015211502", "2015211503", "2015211504"}; //private arraylist<string> alist;@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.class_search); LV=(ListView) Findviewbyid (r.id.lv); Adapter=NewArrayadapter<string> ( This, Android.        R.layout.simple_list_item_1,mstrings);       Lv.setadapter (adapter); //Lv.setadapter (New arrayadapter<string> (this,android. r.layout.simple_list_item_1,mstrings));Lv.settextfilterenabled (true);//set LV can be filteredsv=(Searchview) Findviewbyid (R.ID.SV); Sv.seticonifiedbydefault (false);//Setting the Searchview default does not automatically shrink to an iconSv.setonquerytextlistener ( This);//setting up event listenersSv.setsubmitbuttonenabled (true);//Set Display Search buttonSv.setqueryhint ("Input class number");//Set default display text    }    //Fire This method when you click the Search button@Override Public Booleanonquerytextsubmit (String query) {return false; }    //The method is fired when the user enters a character@Override Public BooleanOnquerytextchange (String newtext) {if(Textutils.isempty (NewText)) {//Clearing the ListView filterLv.cleartextfilter (); }        Else        {//filter list items for a ListView by using user-entered contentLv.setfiltertext (NewText); }        return false; }}

Above is the Classsearch code

About the ListView, begin to error in ARRAYADAPTER&LT;STRING&GT;, the error is pointing to a null pointer. The main reason for the error here is Setcontentview (R.layout.class_search), because the direction of the wrong so rightfully called has been a null pointer.Be sure to see which layout you are calling. Before there are two layout, reference errors caused by the error, and later I was impatient, directly deleted another, only to find the error here, written another layout.  about Searchview, error insv= (Searchview) Findviewbyid (R.ID.SV), the error is:Android.widget.SearchView cannot is cast to Android.support.v7.widget.SearchViewThe solution to this error iswill beImport Android.support.v7.widget.SearchView change to import Android.widget.SearchViewsolved (though not known for God's horse)

Android in 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.