Android search box Searchview usage-android learning Journey (39)

Source: Internet
Author: User

Searchview Introduction

Searchview is a search box component that allows users to search for text and then display it. ‘

code example

This example adds a dress moth listview to add auto-completion to the Searchview.

 PackagePeng.liu.test;Importandroid.app.Activity;ImportAndroid.graphics.Color;Importandroid.graphics.drawable.Drawable;ImportAndroid.os.Bundle;ImportAndroid.text.TextUtils;Importandroid.view.Gravity;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.widget.AdapterView;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.BaseAdapter;ImportAndroid.widget.Button;ImportAndroid.widget.CalendarView;ImportAndroid.widget.DatePicker;ImportAndroid.widget.EditText;ImportAndroid.widget.FrameLayout;ImportAndroid.widget.GridView;ImportAndroid.widget.ImageSwitcher;ImportAndroid.widget.ImageView;ImportAndroid.widget.LinearLayout;ImportAndroid.widget.ListView;ImportAndroid.widget.NumberPicker;ImportAndroid.widget.SearchView;ImportAndroid.widget.SimpleAdapter;ImportAndroid.widget.TextSwitcher;ImportAndroid.widget.TextView;ImportAndroid.widget.TimePicker;ImportAndroid.widget.Toast;ImportAndroid.widget.ViewFlipper;ImportAndroid.widget.ViewSwitcher;ImportJava.util.ArrayList;ImportJava.util.Calendar;ImportJava.util.HashMap;ImportJava.util.List;ImportJava.util.Map; Public  class mainactivity extends Activity implements Searchview . Onquerytextlistener {    Privatestring[] STRs =Newstring[]{"Java","Python","HTML"};PrivateListView list;PrivateSearchview Searchview;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);        List = (ListView) Findviewbyid (r.id.list); List.setadapter (NewArrayadapter<string > ( ThisAndroid.        R.layout.simple_list_item_1,strs)); List.settextfilterenabled (true);        Searchview = (Searchview) Findviewbyid (R.ID.SV); Searchview.seticonifiedbydefault (false); Searchview.setonquerytextlistener ( This); Searchview.setsubmitbuttonenabled (true); Searchview.setqueryhint ("Find"); }@Override     Public Boolean Onquerytextsubmit(String s) {Toast.maketext ( This,"Search for Characters"+s,toast.length_long). Show ();return false; }@Override     Public Boolean Onquerytextchange(String s) {if(Textutils.isempty (s))        {List.cleartextfilter (); }Else{List.setfiltertext (s); }return true; }}
<?xml version= "1.0" encoding= "Utf-8"?><LinearLayout xmlns: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" Android:paddingleft="@dimen/activity_horizontal_margin"Android:paddingright="@dimen/activity_horizontal_margin"Android:paddingtop="@dimen/activity_vertical_margin"Android:paddingbottom="@dimen/activity_vertical_margin"Tools:context=". Mainactivity "android:orientation="Vertical">    <searchviewandroid:layout_width="Wrap_content"android:layout_height ="Wrap_content"android:id="@+id/sv"/>                            <ListViewandroid:layout_width="Match_parent"android:layout_height= "0DP" android:id="@+id/list"android:layout_weight="1" />                                </linearlayout>

Android search box Searchview usage-android learning Journey (39)

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.