Solved

How to add search dialog in current page using Andorid

Posted on 2013-01-23
1
677 Views
Last Modified: 2013-01-27
I have using this code to display search dialog:
public boolean onKeyUp(int keyCode, KeyEvent event)
    {
        if (keyCode == KeyEvent.KEYCODE_SEARCH)
        {
              Intent i = new Intent(stock.this, SearchableActivity.class);
            i.setAction("android.intent.action.SEARCH");
            startActivity(i);          
            return true;
              //Toast.makeText(this, "search button pressed", Toast.LENGTH_LONG).show();
        }
        // TODO Auto-generated method stub
        return super.onKeyUp(keyCode, event);
    }






<activity
            android:name=".SearchableActivity"
            android:launchMode="singleTop" >
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter>

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>



<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:hint="@string/search_hint"
    android:includeInGlobalSearch="true"
    android:label="@string/app_label" >
</searchable>

This code has redirected to next page and show that search dialog. But this dialog should be displayed in current page not redirect to next page. Do you have any example to display search dialog in current window.
0
Comment
Question by:jnj_web_solutions
1 Comment
 
LVL 18

Accepted Solution

by:
dj_alik earned 500 total points
ID: 38815466
The search dialog provides a floating search box at the top of the screen, with the application icon on the left. The search dialog can provide search suggestions as the user types and, when the user executes a search, the system sends the search query to a searchable activity that performs the search. However, if you are developing your application for devices running Android 3.0, you should consider using the search widget instead (see the side box).
The search dialog is always hidden by default, until the user activates it. Your application can activate the search dialog by calling onSearchRequested(). However, this method doesn't work until you enable the search dialog for the activity.

To enable the search dialog, you must indicate to the system which searchable activity should receive search queries from the search dialog, in order to perform searches. For example, in the previous section about Creating a Searchable Activity, a searchable activity named SearchableActivity was created. If you want a separate activity, named OtherActivity, to show the search dialog and deliver searches to SearchableActivity, you must declare in the manifest that SearchableActivity is the searchable activity to use for the search dialog in OtherActivity.

Read about all available implementations:
http://developer.android.com/guide/topics/search/search-dialog.html
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Pictures cut off when texting 13 129
Measure and control tethering schedule 2 39
drive pdf viewer 3 23
How to export SQL to firebase ? 7 72
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question