Android system has browse record search box

Source: Internet
Author: User

First, configure the search description file

To create the sreachable.xml in the XML file in res, it reads as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<searchable
Xmlns:android= "Http://schemas.android.com/apk/res/android"
android:hint= "@string/searchlable"
Android:label= "@string/searchlable"
Android:searchsuggestauthority= "Com.glacier.ui.SearchSuggestionProvider"
Android:searchsuggestselection= "? ">

</searchable>

Second, fill in the configuration file information

1. The configuration of the search box

<!--search Action-->
<intent-filter >
<action android:name= "Android.intent.action.SEARCH" >
</action>
</intent-filter>

<meta-data
Android:name= "Android.app.default_searchable"
Android:value= "Mainactivity"/>
<meta-data
Android:name= "Android.app.searchable"
Android:resource= "@xml/searchable" >
</meta-data>

2. Save the Content configuration

<provider
Android:authorities= "Com.glacier.ui.SearchSuggestionProvider"
Android:name= "Com.glacier.ui.SearchSuggestionProvider" >
</provider>

Third, invoke the Start Search box method

Pop-up search box
Onsearchrequested ();

Can write the system method to do the necessary content to load the other
@Override
public Boolean onsearchrequested () {
Open the floating search box (the first parameter is added by default to the value of the search box)
Startsearch (null, FALSE, NULL, FALSE);
return true;
}

Get search Results
@Override
public void Onnewintent (Intent Intent) {
Super.onnewintent (Intent);
Get the value in the search box
Query=intent.getstringextra (Searchmanager.query);
System.out.println (query);
Save a search record
Searchrecentsuggestions suggestions=new searchrecentsuggestions (Mainactivity.this,
Searchsuggestionprovider.authority, Searchsuggestionprovider.mode);
Suggestions.saverecentquery (query, NULL);
System.out.println ("Save Success");
}

Four, remember to write the storage place

import android.content.searchrecentsuggestionsprovider; 

public class Searchsuggestionprovider extends Searchrecentsuggestionsprovider { 

Public final static String authority= "Com.glacier.ui.SearchSuggestionProvider";  
Public final static int mode=database_mode_queries; 

Public Searchsuggestionprovider () { 
super ();  
Setupsuggestions (authority, MODE);  
} &NBSP
}

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.