Some uses of Xamarin Android Searchview

Source: Internet
Author: User

Objective

Searchview is commonly used in Android search control, there are many online about Searchview are Java, so I refer to the Xamaroin official website Some of the demo to summarize some methods.

Guide

1. How to create a Searchview

Common events for 2.searchview

3. How to use Searchview

Body

1. How to create a Searchview

creating a Searchview is simple, we just need to create a new layout file and rewrite the oncreateoptionsmenu.

, create a new folder named menu under the Resources folder and create a new XML layout file within the folder.

Search.xml

<?XML version= "1.0" encoding= "Utf-8"?> <Menuxmlns:android= "Http://schemas.android.com/apk/res/android">  <ItemAndroid:id= "@+id/search"Android:title= "Search"android:showasaction= "Ifroom"Android:actionviewclass= "Android.widget.SearchView" />  </Menu>

so our layout file is built, and then rewrite the oncreateoptionsmenu.

 Public Override BOOL oncreateoptionsmenu (Imenu menu)        {            menuinflater.inflate (Resource.Menu.search, Menu);             var searchview = (Searchview) menu. FindItem (Resource.Id.search). Actionview; return true ;        }

The end result is as follows:

This way our searchview is created.

The Main method of 2.searchview

The role of Searchview is to search, and the events we commonly use include the following:

Onquerytextlistener called when the query content has changed

Oncloselistener Called when Searchview is closed

Onquerytextchange The new content of the text field of the query, which is equivalent to writing edge search

onquerytextsubmit Querying the content of the query to be submitted

onClose events that are triggered when Searchview is turned off

Here's how you can use the code to illustrate the usage of these kinds of events

3. How to use Searchview

Call this method first to inherit the Searchview class

 Public class Activity1:searchview.ionquerytextlistener,searchview.ioncloselistener

This also inherits Ionquerytextlistener and Ioncloselistener, and if you do not inherit this class, you will be prompted for an error that the type cannot be converted.

After the inheritance we can set the listener event, also rewrite the oncreateoptionsmenu.

Searchview.setonquerytextlistener (this), Searchview.setoncloselistener (this);

after setting up the listener event, you can override these methods

 Public BOOLOnquerytextchange (stringNewText) {                  return true; }         Public BOOLOnquerytextsubmit (stringquery) {                        return true; }         Public BOOLOnClose () {return true; }

Photo Demo

Some uses of Xamarin Android 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.