Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 694
  • Last Modified:

How to add search dialog in current page using Andorid

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
jnj_web_solutions
Asked:
jnj_web_solutions
1 Solution
 
dj_alikCommented:
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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now