danielrvt-sgb
danielrvt-sgb

Reputation: 1138

Don´t launch a new Activity when selecting a search suggestion Android

I'm developing an android app, and I've been watching some examples from the sdk, in particular the Dictionary example. The problem is that all this examples launch a new activity when a search suggestion is selected.

The way my app works, that is not good for me, I have to center a map in some point wich is in the background of the same activity with displays the suggestions.

Anyone knows how to catch the intent but not launch an activity?

Upvotes: 2

Views: 170

Answers (2)

Javi Martínez
Javi Martínez

Reputation: 512

There is a better and faster way. Simply add:

android:launchMode="singleTop"

In your activity section from AndroidManifest.xml

Upvotes: 2

jbihan
jbihan

Reputation: 3099

In the Searchable Dictionary sample, in SearchableDictionay.java you have a method called

private void showResults(String query)

This method displays the results of the search of query in a list. The launch of the activity is triggered when the user clicks on an item in this list, and this is performed in the method

public void onItemClick(AdapterView<?> parent, View view, int position, long id)  

of the listener on the listview :

mListView.setOnItemClickListener(new OnItemClickListener()

If you want to launch your own method, you just have to re-write the code inside that method (for example, to center a map...) :

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    centerMap();
}

(centerMap() being a method declared in the same class and doing some processing)

Upvotes: 0

Related Questions