0

I am new in android and I am working with a search related feature. After read the tutorial I have some questions:

1 Does the SearchableActivity unique in an application?

It seems that 3 steps are required to setup the search feature(from the android developer guide):

1)create the SearchableActivity to receive the search keyword.

2)make the SearchableActivity to accept the ACTION_SEARCH intent

3)specify the searchable configuration to use, in a element.

Then I wonder if all the search related job will be delegated to the SearchableActivity?

And suppose I have two MainActivity and MainActivityTwo, both of them make a SearchView inside the action bar.

The AndroidMinefset.xml:

    <activity android:name="com.app.activity.MainActivityTwo" />
    <activity android:name="com.app.activity.MainActivity" />
    <activity android:name="com.app.activity.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/search.xml:

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:hint="@string/search_hint"
    android:label="@string/app_name" >
</searchable>

And register the search configuration(serchableInfo) toSerchView:

.MainActivity

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.u_action_menu_map, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));  
    return super.onCreateOptionsMenu(menu);
}

This does not work, it seems that there is no serchableInfo bound with the current Activity(MainActivity).

Even I changed to this:

searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName("com.app.activity", "SearchableActivity")));

It still cannot find the searchableInfo.

After I add the search related configuration to MainActivity:

<activity android:name="com.app.activity.MainActivityTwo" />
<activity android:name="com.app.activity.SearchableActivity" />
<activity android:name="com.app.activity.MainActivity"
            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>

This worked. WTF.

I always thought that the Activity provide the Search UI and the Activity handle the input are different, but after my test it seems that they are the same Activity, that't to say the user input are submit to the Activity itself,but why use the **ing intent to transfer the input data?

2 The search submit

The Search dialog have a search submit button at the right of the dialog:

enter image description here

But there is nothing inside the SearchView so how to submit the search in a SearchView:

enter image description here

Szymon
  • 42,577
  • 16
  • 96
  • 114
hguser
  • 35,079
  • 54
  • 159
  • 293

1 Answers1

1

There should be a search key on your keyboard. It can also be go, return or similar keys that should start the search.

enter image description here

Szymon
  • 42,577
  • 16
  • 96
  • 114