Solved

How to add search dialog in current page using Andorid

Posted on 2013-01-23
1
668 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

First off, some of you reading this are already thinking there is an error in the title. It really should be Kindle Fire versus OTHER Android tablets. That's because the Amazon Kindle Fire IS an Android tablet. Well, it is and it's not. It's running…
If your app took Google’s lash recently, here are the 5 most likely reasons.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now