Search in a list - android

I am trying to implement a search menu for my app.I made a menu "seach",in onOptionsItemSelected I have:
if (item.getItemId()==R.id.search) {
onSearchRequested();
return(true);
I put in strings.xml :
<string name="searchLabel">Lists</string>
<string name="searchHint">search</string>
and in searchable.xml :
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/searchLabel"
android:hint="#string/searchHint" />
but nothing happens after I type something. What means "Lists" from strings.xml?
Where is my mistake?

This topic is covered in Android developer guide here:

Don't forget you need to tell Android about your search activity in your AndroidManifest.xml
<activity
android:name=".ui.SearchActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action
android:name="android.intent.action.SEARCH" />
<action
android:name="android.intent.action.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>

Related

searchable activity, handle event

In an Android's search activity, is it possible to handle the event when the user touches the cross button to clear the search box?
The button I'm talking about is the cross in the screenshot:
This is the definition on the manifest:
<activity
android:name=".MySearchActivity"
android:theme="#android:style/Theme.Dialog">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
This is the xml referenced on the meta-data:
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/search_hint" />
use SearchView.OnQueryTextListener interface, in particular see onQueryTextChange(String newText) method

Android first app, all activities visible in menu

I just created my first Android app, all works fine, but all of the activities are shown on my Android menu. What did I do wrong?
Screenshot: imgur.com/9CmXU
I want to have one icon, directing to MainActivity, not all activities
<!-- language-all: lang-html -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myApps.birthdaymeter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/my_logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".BirthdayMeter"
android:label="#string/title_activity_birthday_meter" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AboutWindow"
android:label="#string/title_activity_about_window" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShowResult"
android:label="#string/title_activity_show_result" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is my manifest, changing logo didn't help
The <intent-filter> tag is used to describe the type of Intents that each Activity will respond to. The "android.intent.action.MAIN" action says that this Activity is an entrance point for your Application (think the main method that a java program requires). The "android.intent.category.LAUNCHER" category tells the OS to display the Activity in your list of Applications. Adding the DEFAULT category is ok, but effectively the same as omitting the <intent-filter> tag completely (which I find to make for much cleaner and easier to read code). You should only be using the <intent-filter> tag with these two actions and categories on the Activity that starts when a user opens your app. If wanted an Activity within your application to be able to respond to some special intents, you would use the tag to define which it responds to.
Here's a link to the google dev pages to help you learn more about Intent Filters.
http://developer.android.com/guide/components/intents-filters.html
Here's the documentation for the <intent-filter> tag. It's not the easiest to understand though.
http://developer.android.com/guide/topics/manifest/intent-filter-element.html
And here's the docs for the Manifest file and the Intent class. Both of these are good for reference if you're not sure about which tags to use in your Manifest. Good luck!
http://developer.android.com/guide/topics/manifest/manifest-intro.html
http://developer.android.com/reference/android/content/Intent.html
You phrased your question extremely generally, so I am not sure what to answer. It seems like you haven't called nameOfActivity.this.finish() when you launched another activity
If you post your manifest file I can help a little more, but it looks to me like you have not declared your activities correctly.
It should be setup somewhat like this:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="Activity1"></activity>
<activity android:name="Activity2"></activity>
<activity android:name="Activity3"></activity>
</application>
Essentially, create an application declaration, and then include each activity within it.

Android Manifest File Not Picking Up Default Launch Activity

If on run/debug configuration, if I specify a launch activity, then my app runs fine, but when I select 'Launch Default Activity' I get "No Launcher activity found!" error from android adb despite the fact that I have specified the launch activity in my manifest file. I'm using android 2.1.
I've tried refreshing the file/project, clean and rebuild, deleting the file and re-writing it, creating a new project and copy/pasting all the code across and doing Android Tools -> Fix Project Properties. I've tried Android Tools-> Rename Application Package, which prompts me to update the project launch configuration (to which I say yes, but it still doesn't fix the problem).
I've also tried different devices. My Home activity extends another activity and is in its own Home.java file in my src folder. This is what my manifest file looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.geogreenweb.localvore"
android:versionCode="1"
android:versionName="1.0">
<application
android:icon="#drawable/icon"
android:label="#string/general_app_name"
android:debuggable="true">
<meta-data android:name="android.app.default_searchable"
android:value=".localvorebeta6" />
<activity android:name="com.geogreenweb.localvore.Home"
android:label="#string/general_app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Quit"
android:label="Quit">
</activity>
<activity android:name="com.geogreenweb.localvore.InSeason"
android:label="In Season">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.List"
android:label="A - Z">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Local"
android:label="Local"
android:configChanges="orientation"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Details"
android:label="Details">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Search"
android:label="Search">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Map"
android:label="Map"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Help"
android:label="Help">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="7" />
</manifest>
UPDATE: I changed one of the activity labels, and the different label appears in the app, so the changes to the manifest file are being picked up, but still I get the No Launch Activity error
UPDATE 2: I managed to solve the problem by creating a new project in the end, but only if I select the option to create an activity when making the new project, then copy/paste in the rest of the stuff into the project
if you remove the :
<action android:name="android.intent.action.SEARCH" />
it will launch normally.
i don't know why .. it just worked for me. i'm still searching why?!!
UPDATE 1:
i found this:
No Launcher activity found, despite being declared in manifest.xml
still don't know why? .. still searching for it.
UPDATE 2: GOT IT!
http://developer.android.com/guide/topics/intents/intents-filters.html
A filter has fields that parallel the action, data, and category fields of an Intent object. An implicit intent is tested against the filter in all three areas. To be delivered to the component that owns the filter, it must pass all three tests. If it fails even one of them, the Android system won't deliver it to the component — at least not on the basis of that filter. However, since a component can have multiple intent filters, an intent that does not pass through one of a component's filters might make it through on another.
in our case this means that the system sends an intent with the MAIN action and LAUNCH category. it finds an with the following:
MAIN action ..............[ pass ]
LAUNCH category .... [ pass ]
SEARCH action .........[ fail ]
but .. if you put the SEARCH action in another , the containing the MAIN and LAUNCHER criteria passes.
The only thing I can think of is the lines
<activity android:name="com.geogreenweb.localvore.Home"
Try using just
<activity android:name=".Home"
instead
Try adding the following to your main launcher Activity right next to the launcher category element.
<category android:name="android.intent.category.DEFAULT"/>

How to add quick search box to our application?

How to add quick search box (QSB) to our application?
Check this page on more info about the QSB in android.
and add this to your activity in the manifest
<activity android:name=".MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>

How do I invoke the search dialog using onSearchRequested()

I'm trying to implement the search dialog and I am unable to display the search from an Activity.
I have my main activity defined in my manifest file, this activity shows the user a list of options they have to choose from. One of the options is a Search option.
<activity
android:name=".MenuListActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
My Search activity is defined in my manifest file like so.
<activity android:name=".SearchActivity"
android:launchMode="singleTop"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
Now my problem is when I call the onSearchRequested() from my MenuListActivity nothing happens.
public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {
String strText = items[position];
if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_browse))) {
startActivity(new Intent(MenuListActivity.this, WSMobileActivity.class));
} else if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_search))) {
// If i call it like this it doesn't work, nothing happens
onSearchRequested();
} else if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_locator))) {
startActivity(new Intent(MenuListActivity.this, StoreLocatorActivity.class));
}
}
Please help, how do I invoke the search request from my MenuActivity?
did you check your res/xml/searchable.xml?
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="#string/search_hint"
android:label="#string/search_label">
</searchable>
Search dialog doesn't show up when you have hard coded strings for hint and label. They have to be #string resources.
Also, there is no need to call or override the onSearchRequested() method in your calling activity unless you want to invoke search from one of your UI widgets like a Button or a ListItem.
Apart from declaring the SearchActivity in the manifest file you need to include the meta-data info.
If you want to invoke the search dialog throughout the application then include
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
inside the application tag.
If you want to invoke the search dialog only in a particular activity then include
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
inside the activity tag.
for more details please refer
http://developer.android.com/guide/topics/search/search-dialog.html.
You are missing tag in your activity tag in manifest. replace your activity declaration by following.
<activity
android:name=".MenuListActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchActivity" />
</activity>
I've done all that but still cannot see the search dialog on API 17. It works however after adding
android:actionViewClass="android.widget.SearchView"
in the fragment menu
<item
android:id="#+id/menu_item_search"
android:actionViewClass="android.widget.SearchView"
android:icon="#android:drawable/ic_menu_search"
android:showAsAction="ifRoom"
android:title="#string/search"/>

Categories

Resources