2012-03-14 16 views
7

Hola estoy usando android 3.0 widget de búsqueda (no el modo de búsqueda), el problema es que necesito pasar algunos parámetros junto con la palabra de búsqueda.android paquete de pase con búsqueda

Android no está llamando a cualquiera de estos

searchManager.setOnDismissListener(new OnDismissListener() { 

      @Override 
      public void onDismiss() { 
       // TODO Auto-generated method stub 
       Log.v(MyApp.TAG, "on dismiss search"); 

      } 
     }); 

     searchManager.setOnCancelListener(new OnCancelListener() { 

      @Override 
      public void onCancel() { 
       // TODO Auto-generated method stub 
       Log.v(MyApp.TAG, "on dismiss cancel"); 

      } 
     }); 

@Override 
    public boolean onSearchRequested() { 
     Bundle appData = new Bundle(); 
     appData.putLong("listino_id", this.listino_id); 
     this.startSearch(null, true, appData, false); 
     return true; 
     // return super.onSearchRequested(); 
    } 

Necesito mi actividad a NO ser singleOnTop, aquí es mi AndroidManifest.xml

<activity android:name=".activity.ListinoProdottiActivity" android:windowSoftInputMode="stateHidden"> 


      <!-- Receives the search request. --> 
      <intent-filter> 
       <action android:name="android.intent.action.SEARCH" /> 
       <!-- No category needed, because the Intent will specify this class component--> 
      </intent-filter> 

        <!-- enable the base activity to send searches to itself --> 
      <meta-data android:name="android.app.default_searchable" 
       android:value=".activity.ListinoProdottiActivity" /> 


      <!-- Points to searchable meta data. --> 
      <meta-data android:name="android.app.searchable" 
         android:resource="@xml/searchable" /> 

     </activity> 

Aquí está mi searchable.xml

<?xml version="1.0" encoding="utf-8"?> 
<searchable xmlns:android="http://schemas.android.com/apk/res/android" 
    android:label="@string/app_name" 
    /> 
+0

Cuando no pasa el parámetro extra hace ¿funciona? –

+0

no puedo pasar el parámetro adicional, ya que no puedo usar ningún "gancho" para agregar parámetros al Intento, ninguna de esas 3 funciones se llama – max4ever

+0

Pegue el contenido de @ xml/searchable. –

Respuesta

0

Compruebe si usted Tiene cadenas codificadas para android:hint o android:label en res/xml/searchable.xml. Deben ser identificadores de recursos de cadena.

+0

son recursos de cadena – max4ever

6

datos del pasaporte con el paquete de widget de búsqueda:

diseño/Main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="@string/hello" /> 
    <Button android:id="@+id/button" android:text="test" 
     android:layout_width="fill_parent" android:layout_height="wrap_content" /> 
</LinearLayout> 

diseño/searchable.xml:

<?xml version="1.0" encoding="utf-8"?> 
<searchable xmlns:android="http://schemas.android.com/apk/res/android" 
    android:label="@string/search_label" 
    android:hint="@string/search_hint" 
    android:searchMode="showSearchLabelAsBadge" 
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" 
    android:voiceLanguageModel="free_form" 
    android:voicePromptText="@string/search_invoke" 
    android:searchSuggestSelection=" ? " 
/> 

valores/cuerdas .xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<string name="hello">Hello World, SearchTest!</string> 
<string name="app_name">Searchtest</string> 
<string name="search_label">Search Test</string> 
<string name="search_hint">1234</string> 
<string name="search_invoke">234</string> 
<string name="search_query_results">544545</string> 
</resources> 

AndroidManifest.xml:

<application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:label="@string/app_name" 
      android:name=".SearchWidgetExampleTest" > 
      <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=".ResultActivty" /> 
     </activity> 

     <activity android:name=".ResultActivty" 
        android:label="@string/search_query_results"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.SAMPLE_CODE" /> 
      </intent-filter> 
      <intent-filter> 
       <action android:name="android.intent.action.SEARCH" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
      <meta-data android:name="android.app.searchable" 
         android:resource="@layout/searchable" /> 
     </activity> 
    </application> 

ResultActivty.java:

package org.imranandroid.TestSearchexmp; 
import android.app.Activity; 
import android.app.SearchManager; 
import android.os.Bundle; 
import android.widget.Toast; 

public class ResultActivty extends Activity{ 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     Bundle bundled= getIntent().getBundleExtra(SearchManager.APP_DATA); 
     Long ttdata=bundled.getLong("listino_id"); 
     Toast.makeText(this, ttdata.toString(), Toast.LENGTH_SHORT).show(); 
    } 
} 

SearchWidgetExampleTest.java:

package org.imranandroid.TestSearchexmp; 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 

public class SearchWidgetExampleTest extends Activity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     Button button1 = (Button) findViewById(R.id.button); 
     button1.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       onSearchRequested(); 
      } 
     }); 
    } 
    @Override 
    public boolean onSearchRequested() { 
     Bundle appDataBundle = new Bundle(); 
     appDataBundle.putLong("listino_id", 4434724724L); 
     startSearch("imran", false, appDataBundle, false); 
     return true; 
    } 
} 

Happly Coding !!!

+1

gracias, funciona como la búsqueda normal, pero no utiliza el WIDGET de búsqueda, como en http://developer.android.com/guide/topics/search/search-dialog.html#UsingSearchWidget o como en ver la captura de pantalla aquí http://stackoverflow.com/questions/9588810/how-to-hide-unhide-the-actionbar-list-on-android-3 – max4ever

0

Si sus llamadas son sincrónicas (realiza una solicitud de búsqueda y espera respuesta y no realiza ninguna solicitud de búsqueda hasta obtener su respuesta), entonces es fácil.

Simplemente crea una clase estática auxiliar para hacerlo por ti.

algo como esto:

public static Bundle myStaticClass; 
. 
. 
. 
myStaticClass.putString(key, value); 
callSearch(); 
. 
. 
. 
afterSearchResponse(); 
String value = myStaticClass.get(key); 
+0

y esto me ayuda cómo? – max4ever

+0

Ha preguntado sobre la transferencia de datos, así que esta es la forma en que puede hacerlo, si no lo entiendo, edite su pregunta para que sea más comprensible. –

1

cuando se consulta por SearchView (widget de búsqueda SearchView ||) que puede pasar parámetros a searchActivity (searchResultActivity) por definir su propio OnQueryTextListener como este.

searchView.setOnQueryTextListener(new OnQueryTextListener() { 

     @Override 
     public boolean onQueryTextChange(String arg0) { 
      // TODO Auto-generated method stub 
      return false; 
     } 

     @Override 
     public boolean onQueryTextSubmit(String query) { 
      Intent searchIntent = new Intent(getApplicationContext(), SearchResultsActivity.class); 
      searchIntent.putExtra(SearchManager.QUERY, query); 
      searchIntent.setAction(Intent.ACTION_SEARCH); 
      startActivity(searchIntent); 
      return true; 
     } 
    }); 
0

puede utilizar el seguimiento

en el menú

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu_al_ayats, menu); 

    SearchManager searchManager = 
      (SearchManager) getSystemService(Context.SEARCH_SERVICE); 
    SearchView searchView = 
      (SearchView) menu.findItem(R.id.action_search).getActionView(); 
    Bundle appData = new Bundle(); 
    appData.putString("hello", "world"); 

    searchView.setAppSearchData(appData); 

    searchView.setSearchableInfo(
      searchManager.getSearchableInfo(getComponentName())); 

    return true; 
} 

y en su actividad de resultados de búsqueda poner el siguiente

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_activity_search_result); 

    handleIntent(getIntent()); 
} 

    private void handleIntent(Intent intent) { 

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) { 
     String extrastring=intent.getBundleExtra(SearchManager.APP_DATA).getString("hello"); 
     //use the query to search your data somehow 
     getSupportActionBar().setTitle(extrastring); 
    } 
} 
Cuestiones relacionadas